I am new to UWP. I am recording voice input (with MediaCapture
) and then I trying to play it back.
And I am getting the following error
The byte stream type of the given URL is unsupported. (Exception from HRESULT: 0xC00D36C4)
I create is an MP3 file that can be play by double click with player. So the file is 'ok'.
When I try to play it with MediaPlayer I get that error. I tried installing a new codec package and pointed .mp3 at it. Same error. I tried streams, StorageFile and URL methods for defining the input file but always the same error. I have microphone and webcam enabled. (my microphone is in the webcam) I am deploying to 'Local Machine'. Anyone know a possible reason? Here is the code. I would be interested to see if it works on another PC.
private async void RecordAndPlay()
{
string mediaFilename = "audioPRC.mp3";
StorageFile mediaFile;
StorageFolder tempFolder;
MediaCapture mediaCapture;
MediaPlayer mediaPlayer = null;
LowLagMediaRecording lowLagMediaRecording;
MediaSource mediaSource;
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
mediaCapture.Failed += OnMediaCaptureFailed;
tempFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
mediaFile = await tempFolder.CreateFileAsync(mediaFilename, CreationCollisionOption.ReplaceExisting);
MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Medium);
lowLagMediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync(
mediaEncodingProfile, mediaFile);
await lowLagMediaRecording.StartAsync();
// Talk into your microphone during the 10 second wait...
await Task.Delay(10000);
await lowLagMediaRecording.StopAsync();
await lowLagMediaRecording.FinishAsync();
lowLagMediaRecording = null;
mediaPlayer = new MediaPlayer { AutoPlay = false, AudioCategory = MediaPlayerAudioCategory.Media };
mediaPlayer.MediaFailed += OnMediaPlayerFailed;
mediaPlayer.AudioCategory = Windows.Media.Playback.MediaPlayerAudioCategory.Media;
mediaSource = MediaSource.CreateFromStorageFile(mediaFile);
var mediaPlaybackItem = new MediaPlaybackItem(mediaSource);
mediaPlayer.Source = mediaPlaybackItem;
mediaPlayer.Play();
}
private void OnMediaPlayerFailed(object sender, MediaPlayerFailedEventArgs e)
{ Debug.WriteLine(e.ExtendedErrorCode.Message); }
private void OnMediaCaptureFailed(MediaCapture sender, MediaCaptureFailedEventArgs e)
{ Debug.WriteLine("Capture failed: " + e.Message); }
I changed the encoding to a wav file and it all worked. It hasn't really answered the question of why mp3 is failing. Two lines of code changed were:
string mediaFilename = "audioPRC.wav";
MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);
User contributions licensed under CC BY-SA 3.0