문제

In the windows8 Developer preview we can use this code to play audio in background:

mediaElement.AudioCategory = AudioCategory.Media;

In the windows8 Customer perview, It seems that we should use AudioCategory.BackgroundCapableMedia instead of AudioCategory.Media

mediaElement.AudioCategory=AudioCategory.BackgroundCapableMedia;

and I also Declare a background task in appxmanifest

<Extension Category="windows.backgroundTasks" EntryPoint="TestApp.App">
      <BackgroundTasks>
            <Task Type="audio" />
      </BackgroundTasks>
</Extension>

but it didn't work for me and the MediaElement will throw an "MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED“ exception in MediaFailed EventHandler How should I do?

도움이 되었습니까?

해결책

You also need to set up these event handlers:

using Windows.Media;

MediaControl.PlayPressed += MediaControl_PlayPressed;
MediaControl.PausePressed += MediaControl_PausePressed;
MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
MediaControl.StopPressed += MediaControl_StopPressed;

-

void MediaControl_StopPressed(object sender, object e)
{
    myMediaPlayer.Stop();
}

void MediaControl_PlayPauseTogglePressed(object sender, object e)
{
}

void MediaControl_PausePressed(object sender, object e)
{
    myMediaPlayer.Pause();
}

void MediaControl_PlayPressed(object sender, object e)
{
    myMediaPlayer.Play();
}

I think that should have it working.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top