【发布时间】:2018-12-12 19:38:20
【问题描述】:
我对 UWP 还是很陌生。我在测试应用程序 (2D) 中设计的应用程序启动全息应用程序(使用深层链接 - LaunchUriAsync),然后播放一些音频。音频播放机制是通过后台任务完成的。我已遵循 microsoft 的基本文档,但似乎在我处于全息视图时音频不会播放。如果用另一个 2D UWP 应用程序替换全息应用程序,我可以听到音频。
后台任务的片段。
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
}
这里是大部分代码。我也愿意分享整个项目。
【问题讨论】:
标签: c# uwp hololens background-audio