【发布时间】:2015-09-06 20:31:05
【问题描述】:
我正在尝试录制音频并直接播放(我想在耳机中听到我的声音而不保存它)但是 MediaElement 和 MediaCapture 似乎不能同时工作。 我初始化了我的 MediaCapture:
_mediaCaptureManager = new MediaCapture();
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
settings.MediaCategory = MediaCategory.Other;
settings.AudioProcessing = AudioProcessing.Default;
await _mediaCaptureManager.InitializeAsync(settings);
但是我真的不知道如何进行;我想知道其中一种方法是否可行(我尝试实施它们但没有成功,我还没有找到示例):
- 有没有办法使用 StartPreviewAsync() 录制音频,或者它只适用于视频?我注意到在设置 CaptureElement Source 时出现以下错误:“指定的对象或值不存在”;只有当我写“settings.StreamingCaptureMode = StreamingCaptureMode.Audio;”时才会发生虽然一切都适用于 .Video。
- 如何使用 StartRecordToStreamAsync() 录制到流中;我的意思是,我该如何初始化 IRandomAccessStream 并从中读取?我可以写流,同时继续读吗?
-
我读到将 MediaElement 的 AudioCathegory 和 MediaCapture 的 MediaCathegory 更改为 Communication 有可能它可以工作。然而,虽然我的代码在以前的设置下工作(它只需要记录并保存在一个文件中),但如果我写了“settings.MediaCategory = MediaCategory.Communication;”,它就不起作用了。而不是“settings.MediaCategory = MediaCategory.Other;”。你能告诉我为什么吗? 这是我目前的程序,只是记录、保存和播放:
private async void CaptureAudio() { try { _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName); MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto); await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile); _recording = true; } catch (Exception e) { Debug.WriteLine("Failed to capture audio:"+e.Message); } } private async void StopCapture() { if (_recording) { await _mediaCaptureManager.StopRecordAsync(); _recording = false; } } private async void PlayRecordedCapture() { if (!_recording) { var stream = await _recordStorageFile.OpenAsync(FileAccessMode.Read); playbackElement1.AutoPlay = true; playbackElement1.SetSource(stream, _recordStorageFile.FileType); playbackElement1.Play(); } }
如果您有任何建议,我将不胜感激。 祝你有美好的一天。
【问题讨论】:
标签: c# windows-phone-8.1 windows-applications