在 iOS 后台模式下继续从 html5 播放器播放音频 [英] Continue playing audio from html5 player when in iOS background mode

查看:33
本文介绍了在 iOS 后台模式下继续从 html5 播放器播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 html5 和 javascript 以及 Sencha touch 构建了我们面向音乐的应用程序.为了分发,我们用 UIwebView 将它包装在 xcode 中.一切运行良好,除了一件事不起作用:在多任务模式下播放音频.

We built our music-oriented app in html5 and javascript with Sencha touch. For distribution we wrapped it in xcode with UIwebView. Everything runs fine except one thing that does not work: audio playing in multitask mode.

我知道大致思路:在 info.plist 中添加 UIBackgroundModes.

I know the general idea: add the UIBackgroundModes in info.plist.

完成.现在我们甚至可以在后台模式下播放音频了.

Done. Now we can play the audio even in background mode.

直到我们到达歌曲的结尾.要开始下一首歌曲,我们必须再次将应用程序置于前台,或者我们可以点击 iPhone 音频控制器上的播放或下一首歌曲"按钮.

Until we reach the end of the song. To start the next song we have to bring the app to foreground again or we can hit the play or 'next song' button on the iPhone audio controller.

经过一些研究,我在以下位置找到了一个有希望的解决方法:"在 iOS4 上输入背景以播放音频",解决方法是编辑 AVAudioSessionCategoryPlayback 并使用 UIBackgroundTaskIdentifier.我的问题是(就像我迄今为止发现的任何其他修复程序一样)这些解决方案总是假设音频是使用 AVaudioPlayer 或 MPMusicPlayerController 播放的.但在我的情况下,我既不是用户,我们的音频是由包装在 UIwebView 中的 html5 播放器播放的.

After some research I found a promising workaround at: " Entering background on iOS4 to play audio " where the workaround is to edit AVAudioSessionCategoryPlayback and work with the UIBackgroundTaskIdentifier. The problem for me is (just like in any other fix I found so far) that those solutions always assume that the audio is played either with AVaudioPlayer or MPMusicPlayerController. But in my case I user neither, our audio is played by our html5 player wrapped in UIwebView.

当音频播放器是 html5/javascript 播放器时,任何人对如何在 iOS 多任务模式下继续播放音频有什么建议吗?

Anyone has any advice on how to continue playing the audio in iOS multitask mode when the audio player is a html5/javascript player?

推荐答案

谢谢,伙计们,但我最终只是在后台模式下让应用程序忙于循环.这足以弥补连接到播放列表中下一首歌曲的时间.我使用的代码与此类似:iPhone - 后台轮询事件

Thanks, guys, but I ended up simply keeping the app busy in a loop when in background mode. This was enough to bridge the time when connecting to the next song on the playlist. The code I used is similar to this one: iPhone - Backgrounding to poll for events

这篇关于在 iOS 后台模式下继续从 html5 播放器播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆