且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML5 移动应用程序在手机屏幕关闭时运行?

更新时间:2022-12-21 09:32:07

我的音乐应用是HTML5,也需要在后台运行.对此的支持因移动浏览器而异.

My music app is HTML5 and also needs to run in the background. The support for that varies depending on mobile browser.

  • iOS 上的 Safari:将继续在后台播放一两首歌曲
  • Android 上的原生浏览器:将播放一首歌曲然后停止
  • Android 上的 Firefox:将在屏幕锁定、浏览器失去焦点或歌曲结束时停止
  • Android 上的 Dolphin:在后台播放!但最终停止
  • Android 上的 Opera:更好的后台支持,Javascript 继续运行,音乐继续播放,即使屏幕关闭或 Opera 被发送到后台,但最终会在几首歌曲后停止.

如您所见,它是命中还是未命中.有一半的时间我最终试图把手机放在口袋里,试图让屏幕保持打开状态,直到我不小心按下它——这太糟糕了.我渴望有一天用户可以更好地控制在后台运行 HTML5 应用程序.如果我不得不猜测,我会说对此的普遍支持还很遥远,如果它甚至获得牵引力的话.尽管我几乎肯定苹果永远不会批准它,但我***转向原生应用程序解决方案.与此同时,我将保持希望并继续测试最新的移动浏览器.因为如果它真的发生了,那就太棒了.:-)

As you can see it's hit or miss. Half the time I end up trying to put my phone in my pocket backwards, trying to keep the screen on, until I accidentally press it - totally sucks. I long for the day when the user has more control over running HTML5 apps in the background. If I had to guess I would say that universal support for that is very far off, if it ever even gets traction. I'm being forced toward a native app solution even though I am almost positive Apple will never approve it. In the meantime, I'll remain hopeful and keep testing the latest mobile browsers. Because if it actually happens it will be awesome. :-)

我还应该指出,根据我的经验,对于几乎所有上述组合,使用 HTML5 同时运行 javascript、提取网络数据和播放音乐通常会将您的手机变成烤箱并耗尽电池电量迅速地.乌格.

I should also point out that, in my experience, for pretty much all of the above combinations, using HTML5 to simultaneously run javascript, pull network data, and play music will typically turn your phone into an oven and kill your battery pretty quickly. Ugg.

此外,如果您使用的是 jQuery Mobile(这非常棒),您会在不同的浏览器上看到不同的触摸处理.例如,Firefox touch 效果很好,Dolphin 很糟糕,需要精确的触摸并按住并释放才能正确.这不是 HTML5 的直接错误,而是我正在处理的另一个问题.

In addition, if you are using jQuery Mobile (which is mostly fantastic), you will see different touch handling on the different browsers. For example, Firefox touch works great, Dolphin is terrible and requires precise touch-and-hold-and-release to get right. That's not directly HTML5's fault, but another issue I'm dealing with.

这是另一个开发者的有趣的想法在移动 HTML5 上.

Here are another developer's interesting thoughts on mobile HTML5.

更新:我刚刚(2013 年 5 月 22 日)在我的三星 Galaxy S3 上下载了 Opera,它拥有迄今为止***的 HTML5 支持.对于我的应用程序,它会继续在后台运行 javascript,无论屏幕是否关闭,或者 Opera 是否被推送到后台,至少会播放几首歌曲.

UPDATE: I just (May 22, 2013) downloaded Opera on my Samsung Galaxy S3 and it has the best HTML5 support so far. For my app, it continues to run javascript in the background, whether the screen is off, or Opera is pushed to the background, for at least a couple songs.