在UWP中将HTML5音频流保存到mp3文件 [英] In UWP saving HTML5 Audio stream to mp3 file
问题描述
我目前在Windows 10商店中有一个广播流应用程序.现在,我希望为用户提供将当前流录制到mp3文件的可能性.
你们中的任何人对如何保存音频流有任何建议吗?我找不到可以保存字节的属性或事件.
我正在使用Windows.Media.Playback.Mediaplayer类.
预先感谢
基督徒
通常,您无法直接从 Mediaplayer
获取音频流.但是,您可以通过 Stereo Mix
设备监视音频.
将立体声混音"设置为默认录制设备.并通过 MediaCapture
类进行音频捕获.
私有异步任务< bool>RecordProcess(){if(缓冲区!= null){buffer.Dispose();}缓冲区=新的InMemoryRandomAccessStream();if(捕获!= null){capture.Dispose();}尝试{MediaCaptureInitializationSettings设置=新的MediaCaptureInitializationSettings{StreamingCaptureMode = StreamingCaptureMode.Audio};捕获=新的MediaCapture();等待捕获.InitializeAsync(设置);capture.RecordLimitationExceeded + =(MediaCapture发送者)=>{//停止//等待capture.StopRecordAsync();记录=假;抛出新的异常(超出记录限制");};capture.Failed + =(MediaCapture发送者,MediaCaptureFailedEventArgs errorEventArgs)=>{记录=假;抛出新的Exception(string.Format("Code:{0}.{1}",errorEventArgs.Code,errorEventArgs.Message));};}抓住(前例外){如果(ex.InnerException!= null& ex.InnerException.GetType()== typeof(UnauthorizedAccessException)){抛出ex.InnerException;}扔;}返回true;}
请注意, Stereo
只能监视从同一硬件设备输出的音频.因此,您需要设置可用的播放设备.对于代码示例,您可以参考此.>
I currently have a radio streaming App in the Windows 10 Store. Now I want to give my users the possibility to record the current stream to a mp3 File.
Does anyone of you have a suggestion on how to save the Audio Stream? I can't find the property or event that gives me the bytes to save them.
I'm using the Windows.Media.Playback.Mediaplayer class.
Thanks in advance
Christian
In general you could not get Audio Stream from Mediaplayer
directly. However, you could monitor the audio via Stereo Mix
device.
Set Stereo Mix as default record device. And make a audio capture via MediaCapture
class.
private async Task<bool> RecordProcess()
{
if (buffer != null)
{
buffer.Dispose();
}
buffer = new InMemoryRandomAccessStream();
if (capture != null)
{
capture.Dispose();
}
try
{
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Audio
};
capture = new MediaCapture();
await capture.InitializeAsync(settings);
capture.RecordLimitationExceeded += (MediaCapture sender) =>
{
//Stop
// await capture.StopRecordAsync();
record = false;
throw new Exception("Record Limitation Exceeded ");
};
capture.Failed += (MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs) =>
{
record = false;
throw new Exception(string.Format("Code: {0}. {1}", errorEventArgs.Code, errorEventArgs.Message));
};
}
catch (Exception ex)
{
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(UnauthorizedAccessException))
{
throw ex.InnerException;
}
throw;
}
return true;
}
Note that Stereo
could only monitor audio that output from the same hardware device. So you need to set available playback device. For code sample you could refer this.
这篇关于在UWP中将HTML5音频流保存到mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!