windows store app submission failure bacause of not responding Play/Pasue events

Some developers reported that their windows store apps passed WACK test. But they failed to submit to Windows store with following comment:

This app failed to correctly respond to at least one of the play, pause, or play/pause events.

However the paly and pause functions work well in their test machines.

This issue can be caused by following two reasons:

  1. The media file your application plays includes non-English characters. But you declare that your application can be published to English language windows store. In this case, your application will be tested in a pure English OS environment. Since non-English character can’t recognized in pure English OS environment, your submission will fail.
  2. If your application supports background audio, Pause and Resume functions should be supported in system level. But it doesn’t work with some special keyboard which has dedicated Play and Pause keys. Most keyboards only have one toggle button, so MediaControl_PausePressed and MediaControl_PlayPressed aren’t called. That’s why the developer can’t hit this problem.

   Actually when you debug the application, there is a first-chance-exception reported in output window which actually is a RPC_E_WRONG_THREAD error. It means that we should make sure that the Play and Pause function is called in the UI thread instead of working thread. 

              Here is the typical error code

//For support Background Audio

MediaControl.PlayPressed += MediaControl_PlayPressed;

MediaControl.PausePressed += MediaControl_PausePressed;

     

void MediaControl_PlayPressed(object sender, object e)

{

myMediaElement.Play();

}

void MediaControl_PausePressed(object sender, object e)

{

         myMediaElement.Pause();

}

    The solution is that you should call Pause/Play method in UI thread as following:

async void MediaControl_Played(object sender, object e)

{

    await this.Dispatcher.RunAsync

        (Windows.UI.Core.CoreDispatcherPriority.Normal, () =>

        {

            if (myMediaElement.CurrentState == MediaElementState.Paused)

            {

                myMediaElement.Play();

            }

        });

}

 

async void MediaControl_PausePressed(object sender, object e)

{

    await this.Dispatcher.RunAsync

        (Windows.UI.Core.CoreDispatcherPriority.Normal, () =>

        {

            if (myMediaElement.CurrentState == MediaElementState.Playing)

            {

                myMediaElement.Pause();

            }

        });

}