0

我是 UWP 的新手。我正在录制语音输入(使用MediaCapture),然后尝试播放。

我收到以下错误

The byte stream type of the given URL is unsupported. (Exception from HRESULT: 0xC00D36C4)

我创建的是一个可以通过播放器双击播放的 MP3 文件。所以文件是“好的”。

当我尝试使用 MediaPlayer 播放它时,我得到了那个错误。我尝试安装一个新的编解码器包并将 .mp3 指向它。同样的错误。我尝试了流、StorageFile 和 URL 方法来定义输入文件,但总是出现相同的错误。我启用了麦克风和网络摄像头。(我的麦克风在网络摄像头中)我正在部署到“本地机器”。有人知道可能的原因吗?这是代码。我很想看看它是否可以在另一台 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); }
4

1 回答 1

0

我将编码更改为 wav 文件,一切正常。它并没有真正回答为什么 mp3 失败的问题。更改的两行代码是:

        string mediaFilename = "audioPRC.wav";
        MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);
于 2017-03-25T14:10:30.393 回答