简体   繁体   中英

Phonegap HTML5 audio does not resume playback after incoming phone call on iPhone

I have created an app with PhoneGap that plays music from an online stream. It continues playing in background while the iPhone is locked but, and it stops when an incoming phone call arrives.

The problem is that when the phone call ends, music does not sound anymore. I use an HTML5 audio element to play the stream, and my app traces show me that play and playing HTML5 audio element events are triggered after phone call ends.

However, it simply does not produce any music or sound at all.

Hook up to the pause and resume events of Cordova in your app, if you're in paused state, then your app is suspended and would not play anything. You should invoke your play function on the resume event. Fore more info see Events: http://cordova.apache.org/docs/en/2.6.0/cordova_events_events.md.html#Events

it happens when play command is executed before audio device enabled for your app.

yeah it is because of the app shutdown when your call arrives, to get back to app & to play audio it requires some seconds, in short it requires some seconds to start audio device after your call ends.if your play instruction executed before audio device is initiated for your application

you can solve this by cordova's resume event

As an android programmer, there are similar issues. When dealing with CordovaWeb views doing HTML5, if the activity is interrupted for something else, such as a phone call, it needs to be handled in code. In Android, when there is an interrupt, onPause or similar is called. Inside of that, you would need to save state, and the URL of the page for the webview.

When you navigate back, you need to restore the state.

I know i am speaking in Android while this is iOS, but there is some overlap when doing stuff like that.

See: Save & restoring WebView in an embedded PhoneGap app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM