Windows phone 7 - 无法播放锁定屏幕下的音频
问题描述:
我正在为windows phone 7开发一个应用程序。有一个媒体元素可以播放来自url的视频。当我锁定手机时,音频和视频停止播放。我试过禁用ApplicationIdleDetetction,并且我已经处理了Rootframe Obscured和Unobscured。我无法弄清楚手机锁定时如何继续播放音频。Windows phone 7 - 无法播放锁定屏幕下的音频
对此非常感谢!
感谢 格雷厄姆
答
当屏幕锁定时,视频将自动停止播放 - 这是一种内置系统功能。把它看作是一种应用程序的失效保护措施,通过在后台播放视频来消耗设备电池,无论如何这是一项不必要的任务 - 谁在观看内容? ApplicationIdleDetection
根本无助于此任务。
如果您有单独的音频流,则可以使用AudioPlayerAgent,它可用于播放本地和远程音频流。
阅读本:
答
您可以使用调度计时器做到这一点。下面是我如何做到这一点在我的应用程序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;
}
}
这工作(此功能尚未在市场上,即将更新很快!)!其实我只需要调用一个BackgroundPlayer实例。谢谢 ! – jgraham 2012-04-11 18:30:37