UWP Background audio not working when switched to Holographic mode

196 Views Asked by At

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.

Snippet for background task.

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.

1

There are 1 best solutions below

0
fullstack_realm On

Found out the MediaPlayer.AudioCategory was not set to Media. This was restricting audio to override the gamemedia streams from the holographic app.

This SOLVED the problem !