gpt4 book ai didi

uwp - 是否可以在最小化状态UWP下录制音频

转载 作者:行者123 更新时间:2023-12-02 19:23:37 25 4
gpt4 key购买 nike

我需要在 UWP 中使用录音但是如果应用程序最小化,则录音不起作用。

有没有办法在不使用受限功能的情况下做到这一点?

最佳答案

使用扩展执行 session 。它将允许您的 uwp 应用程序在最小化时录制音频。这是链接https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution了解详情。我已经尝试过了,它对我来说效果很好。添加 EnteredBackground 和 LeavingBackground 事件:

        this.EnteredBackground += AppEnteredBackground;
this.LeavingBackground += AppLeavingBackground;

当检测到事件时,调用BeginExtendedExecution,当允​​许 session 时,调用捕获音频函数。

   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;
}


}

您可以采取https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/ExtendedExecution/cs/Scenario1_UnspecifiedReason.xaml.cs例如。

关于uwp - 是否可以在最小化状态UWP下录制音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62701287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com