我需要在UWP中使用录音,但是如果将App最小化,则录音将不起作用。
有什么方法可以在不使用受限功能的情况下做到这一点?
使用ExtendedExecutionSession。它将使您的uwp应用程序在最小化的情况下录制音频。有关详细信息,这里是链接https://docs.microsoft.com/zh-cn/windows/uwp/launch-resume/run-minimized-with-extended-execution。我已经尝试过了,对我来说效果很好。添加EnteredBackground和LeavingBackground事件:
this.EnteredBackground += AppEnteredBackground;
this.LeavingBackground += AppLeavingBackground;
检测到事件时,请调用BeginExtendedExecution,在允许会话时,请调用捕获音频功能。
private async void BeginExtendedExecution()
{
ClearExtendedExecution();
var newSession = new ExtendedExecutionSession();
newSession.Reason = ExtendedExecutionReason.Unspecified;
newSession.Description = "recording audio";
newSession.Revoked += SessionRevoked;
ExtendedExecutionResult result = await newSession.RequestExtensionAsync();
switch (result)
{
case ExtendedExecutionResult.Allowed:
session = newSession;
RecordingAudio();
break;
default:
case ExtendedExecutionResult.Denied:
newSession.Dispose();
break;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句