简体   繁体   中英

'[3556] Windows.Media.BackgroundPlayback.exe' has exited with code 1 (0x1)

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.

我必须将BackgroundTasks添加到新项目中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM