I am working on a Xamarin UWP app and I am trying to get audio to play in the background. I can get it to play in the foreground just fine with the following code:
private MediaPlayer mediaPlayer;
private string audio;
public void Pause()
{
throw new NotImplementedException();
}
public void Play(string audioUrl)
{z
mediaPlayer = BackgroundMediaPlayer.Current;
if (audio != audioUrl)
{
mediaPlayer.SetUriSource(new Uri(audioUrl));
mediaPlayer.Play();
audio = audioUrl;
}
else
{
mediaPlayer.Play();
}
}
public void Stop()
{
mediaPlayer.Pause();
}
As soon as I add a BackgroundTask to my project I get the titular error:
[3556] Windows.Media.BackgroundPlayback.exe' has exited with code 1 (0x1)
I put everything in the appmanifest correctly. When i remove it from the appmanifest it works just fine in the foreground again.
To be specific the error occurs when I hit the play button in the foreground.
I had to add the BackgroundTasks to a new project