0

我正在为 windows phone 7 开发一个应用程序。有一个媒体元素可以从 url 播放视频。当我锁定手机时,音频和视频停止播放。我已经尝试禁用 ApplicationIdleDetetction 并且我已经处理了 Rootframe Obscured 和 Unobscured。我只是不知道如何在手机锁定时继续播放音频。

非常感谢您对此的任何帮助!

谢谢格雷厄姆

4

3 回答 3

0

即使手机被锁定,也可以使用AudioPlayerAgent保持音乐播放!

检查Windows Phone 代码示例上的“背景音频播放器示例” 。

于 2012-04-11T14:42:46.333 回答
0

屏幕锁定时视频将自动停止播放 - 这是系统内置功能。将其视为通过在后台播放视频会耗尽设备电池电量的应用程序的故障保护,无论如何这是一项不必要的任务 - 谁观看内容?ApplicationIdleDetection根本不会帮助完成这项任务。

如果您有单独的音频流,则可以使用AudioPlayerAgent,它可用于播放本地和远程音频流。

读这个:

于 2012-04-11T16:14:09.200 回答
0

您可以使用调度程序计时器来执行此操作。这是我如何在我的应用程序 Searchler 中执行此操作的示例(此功能尚未在市场中,更新即将推出!)使用可用的 MMP 播放器框架@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;
    }
}
于 2013-01-31T22:45:27.330 回答