当切换到全息模式时,UWP背景音频不起作用 [英] UWP Background audio not working when switched to Holographic mode
问题描述
我对UWP很陌生.我正在测试器应用程序(2D)中设计的应用程序,该应用程序将启动全息应用程序(使用深层链接-LaunchUriAsync),然后播放一些音频.音频回放机制是通过后台任务完成的.我遵循了Microsoft的基本文档,但是在全息视图中,音频似乎无法播放.如果将全息应用程序替换为另一个2D UWP应用程序,我可以听到音频.
I'm quite new to UWP. The app I'm designing in a tester app (2D) that launches a Holographic App (using deep link - LaunchUriAsync) followed by some audio playback. The audio playback mechanism is done through a background task. I have followed the essential documentation from microsoft but it appears the audio won't play when I am in holographic view. If the replace the holographic app with a another 2D UWP app, I can hear the audio.
后台任务的代码段.
protected async override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
base.OnBackgroundActivated(args);
IBackgroundTaskInstance taskInstance = args.TaskInstance;
System.Diagnostics.Debug.WriteLine("Background activated Requested...");
await Task.Delay(10000);
MediaPlayer player = new MediaPlayer();
player.AutoPlay = true;
SystemMediaTransportControls systemMediaTransportControls = player.SystemMediaTransportControls;
systemMediaTransportControls.IsPlayEnabled = true;
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Play video");
player.SetStreamSource(stream);
player.Play(); // audio playback doesn't work in holographic mode
}
这是大多数代码.我也愿意分享整个项目.
Here is most of the code. I'm willing to share the whole project as well.
推荐答案
发现MediaPlayer.AudioCategory
未设置为Media.这是限制音频以覆盖全息应用程序的游戏媒体流.
Found out the MediaPlayer.AudioCategory
was not set to Media. This was restricting audio to override the gamemedia streams from the holographic app.
这解决了问题!
这篇关于当切换到全息模式时,UWP背景音频不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!