一般来说,你不能从中获取音频流Mediaplayer直接。 但是,您可以监视通过音频Stereo Mix设备。
设置立体声混音为预设记录装置。 并通过音频捕捉MediaCapture类。
private async Task 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;
}
需要注意的是Stereo只能监控从相同的硬件设备的音频输出的那个。 所以,你需要设置可用的播放设备。 对于代码示例,你可以参考这个 。