如何让应用程序在屏幕锁定下继续运行?

发布于 2024-10-29 05:09:40 字数 667 浏览 2 评论 0原文

我正在编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2024-11-05 05:09:40

这篇博文可能会有所帮助: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文