0

I am developing an app for windows phone 7. There is a media element which plays video from a url. When i lock the phone, the audio and video stops playing. I have tried disabling ApplicationIdleDetetction and i have handled Rootframe Obscured and Unobscured. I just couldn't figure out how to continue playing the audio when the phone is locked.

Any help on this is greatly appreciated !!

thanks graham

jgraham
  • 3
  • 2

3 Answers3

0

Use the AudioPlayerAgent to keep the music playing even when the phone gets locked!

Check the "Background Audio Player Sample" on the Windows Phone Code Samples.

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
0

Video will automatically stop playing when the screen is locked - that is a built-in system feature. Think of it as a fail-safe for applications that will drain the device battery by playing video in the background, which is an unnecessary task anyway - who watches the content? ApplicationIdleDetection won't help with this task at all.

If you have a separate audio stream, you could use AudioPlayerAgent, that can be used to play both local and remote audio streams.

Read this:

Den
  • 16,686
  • 4
  • 47
  • 87
0

You can do this with a dispatcher timer. Here is an example of how I do it in my app Searchler (This feature not yet in marketplace, update coming very soon!) using the MMP Player Framework available @ http://smf.codeplex.com/

namespace Searchler.Views
{
    public partial class PlayerView : PhoneApplicationPage
    {
        bool appUnderLock = false;
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
    }

     public PlayerView()
    {

        InitializeComponent();

        //Hack to enable play under lock screen
        UIThread.Invoke(() => VideoPlayer.PlayStateChanged += VideoPlayer_PlayStateChanged);
        UIThread.Invoke(() => (Application.Current as App).RootFrame.Obscured += RootFrame_Obscured);
        UIThread.Invoke(() => (Application.Current as App).RootFrame.Unobscured += RootFrame_Unobscured);
        dispatcherTimer.Tick += dispatcherTimer_Tick;
        dispatcherTimer.Interval = new TimeSpan(0, 0, 3); 
    }

    void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        if( VideoPlayer.PlaybackPosition == VideoPlayer.EndPosition)
            ((PlayerViewModel)DataContext).Next();  //Custom GetNext Video Method
    }

    void RootFrame_Unobscured(object sender, EventArgs e)
    {
        dispatcherTimer.Stop();
        appUnderLock = false;
    }

    void RootFrame_Obscured(object sender, ObscuredEventArgs e)
    {
        dispatcherTimer.Start();
        appUnderLock = true;
    }
}
Paul DeCarlo
  • 416
  • 2
  • 10