locked
Does MediaPlayer.MediaStateChanged trigger under lock screen? RRS feed

  • Question

  • I am using the mediaplayer to play a custom playlist that should continue when the phone is locked. However the event handler for MediaPlayer.MediaStateChanged doesn't seem to run when the phone is locked even when ApplicationIdleDetectionMode is disabled.

    i have the following code

    PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
    MediaPlayer.MediaStateChanged += HandleSongQueue;
    
    
    // decides when to go to next song
    private void HandleSongQueue(object sender, EventArgs e)
            {
    // if conditions are met
                if (MediaPlayer.State == MediaState.Paused && MediaPlayer.PlayPosition == new TimeSpan(0, 0, 0) && Playlist.IsActive == true)
                {
    // plays the next song
                    General.GeneralFunctions.PlayNext();
                }
            }

    Thursday, July 11, 2013 12:19 AM

Answers

  • I did a quick test, modifying the Music Videos Hub sample (upgraded to target WP8), and was able to get MediaStateChanged event while running under lock...

    Is your project targeting Windows Phone OS 7.1 or 8.0?

    If targeting 7.1 ... do you get the same behave if run on 8.0 phone?


    -Eric.

    • Marked as answer by chickensouple Friday, July 19, 2013 10:42 PM
    Thursday, July 11, 2013 7:57 PM

All replies

  • I did a quick test, modifying the Music Videos Hub sample (upgraded to target WP8), and was able to get MediaStateChanged event while running under lock...

    Is your project targeting Windows Phone OS 7.1 or 8.0?

    If targeting 7.1 ... do you get the same behave if run on 8.0 phone?


    -Eric.

    • Marked as answer by chickensouple Friday, July 19, 2013 10:42 PM
    Thursday, July 11, 2013 7:57 PM
  • I'm testing on 8.0. After further testing, it seems the event handler does run (i added a counter to see if it would add while under lock screen), however it doesn't properly execute PlayNext() (which executes perfectly while not under lock screen)

    my PlayNext() function looks like

    public static void PlayNext()
            {
                    // in case somehow this gets called when the queue is empty
                    if (Queue.SongList.Count == 0)
                    {
                        return;
                    }
    
                    if ((MusicOrganizer.App.Current as MusicOrganizer.App).AppData.Shuffle == true)
                    {
                        Queue.Current = (MusicOrganizer.App.Current as MusicOrganizer.App).RandGenerator.Next(Queue.SongList.Count);
                    }
                    else
                    {
                        if (Queue.Current + 1 >= Queue.SongList.Count)
                        {
                            Queue.Current = 0;
                        }
                        else
                        {
                            ++Queue.Current;
                        }
                    }
                    MediaPlayer.Play(Queue.SongList[Queue.Current].SongSource);
                }
            }
    is there any part of the API that is disabled under lock screen that would affect this?


    • Edited by chickensouple Thursday, July 11, 2013 10:47 PM added afterthought
    Thursday, July 11, 2013 10:46 PM
  • Hi,

    I had the same problem. Under lock screen and after the song is finished, the media player is in stopped state instead paused.

    Tuesday, July 30, 2013 6:47 PM