سؤال

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