【发布时间】:2014-09-07 13:11:34
【问题描述】:
使用MediaElement 控件和MediaCapture 类,我正在尝试同时录制麦克风输入和播放音频。
只要我开始录音,播放的任何曲目都会静音。我认为它不会停止,因为在录制停止后它会继续播放。我在 MediaElement 上的几个事件中添加了挂钩,但没有一个被触发。例如,CurrentStateChanged、MediaEnded、MediaFailed 等。
录制代码:
public async void InitializeMediaCapture()
{
_mediaCaptureManager = new MediaCapture();
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
settings.MediaCategory = MediaCategory.Other;
await _mediaCaptureManager.InitializeAsync(settings);
}
private async void CaptureAudio()
{
_recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
var recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);
await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);
//audio playback stops on preceding line of code
}
我在 MediaElement 上使用 .Play() 来播放音频,并在我的 XAML 中使用控件并将音频源设置在那里。
<MediaElement x:Name="playbackElement"
Source="ms-appx:///Audio/Song.mp3"
AutoPlay="False" />
我也尝试将音频播放为 BackgroundAudio,但这也不起作用。有任何想法吗?
【问题讨论】:
标签: c# windows-phone-8 windows-phone-8.1