【问题标题】:UWP Background audio not working when switched to Holographic mode切换到全息模式时,UWP 背景音频不起作用
【发布时间】: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


    【解决方案1】:

    发现MediaPlayer.AudioCategory 未设置为媒体。这是限制音频以覆盖来自全息应用程序的游戏媒体流。

    这解决了问题!

    【讨论】:

      猜你喜欢
      • 2021-10-19
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      相关资源
      最近更新 更多