如何让应用程序在屏幕锁定下继续运行?
我正在编写一个 WP7 应用程序,即使激活屏幕锁定也需要播放音乐。我已经完成了以下操作:
PhoneApplicationService.Current.ApplicationIdleDetectionMode =
IdleDetectionMode.Disabled;
并且还实现了以下事件:
void RootFrame_Obscured(Object sender, ObscuredEventArgs e)
{
_playunderLock = true;
}
void RootFrame_Unobscured(object sender, EventArgs e)
{
_playunderLock = false;
}
但是当明确按下锁定按钮时,我的音乐仍然停止!
我错过了什么吗? 此外,当音乐播放时,默认锁定屏幕现在不会激活,即使我没有打电话
PhoneApplicationService.Current.UserIdleDetectionMode =
IdleDetectionMode.Disabled;
I am writing a WP7 application which requires to play music even when screen lock is activated. I have done the following:
PhoneApplicationService.Current.ApplicationIdleDetectionMode =
IdleDetectionMode.Disabled;
and am also implementing the events as follows :
void RootFrame_Obscured(Object sender, ObscuredEventArgs e)
{
_playunderLock = true;
}
void RootFrame_Unobscured(object sender, EventArgs e)
{
_playunderLock = false;
}
But my music still stops when the lock button is explicitly pressed!
Am I missing something??
Also when music is playing the default lock screen does not get activated now, even though I haven't called
PhoneApplicationService.Current.UserIdleDetectionMode =
IdleDetectionMode.Disabled;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这篇博文可能会有所帮助:http://andreassauemont.com/post/1068697622/useridledetectionmode-and -应用程序空闲检测模式。如果您需要应用程序在用户未与其交互(例如听背景音乐)时保持运行,则需要禁用用户空闲检测:
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
但从您的描述来看,听起来您在用户锁定屏幕时遇到了问题,这是应用程序空闲检测。所以,我唯一能想到的是你设置得太早了(我知道听起来很奇怪!)。在 RunKeeper 中,我们在 App.xaml.cs 的 InitializePhoneApplication 方法中禁用应用程序空闲检测(*)。(*) 注意: 禁用任何类型的空闲检测是需要用户许可的任何操作,因此您也需要将其添加到您的应用程序中。
This blog post may help: http://andreassaudemont.com/post/1068697622/useridledetectionmode-and-applicationidledetectionmode. If you need the application to keep running while the user isn't interacting with it (such as listening to backgorund music) then you need to disable user idle detection:
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
but from your description it sounds like you are having the problem when the user locks the screen, which is application idle detection. So, the only thing I can think is that you are setting it too early (sounds odd I know!). In RunKeeper we disable application idle detection(*) in the InitializePhoneApplication method in App.xaml.cs.(*) NOTE: Disabling idle detection of any type is any action that requires permission from the user, so you'll need to add this into your application, too.