Is it possible to keep the audio playing inside a WebView still play when an App is suspended or in background on Windows 10 or Windows Phone 8?
Correctly if in Windows 10, if an App is not focus the webview keeps playing, but in tablet mode if goes to background, the sound is muted.
Thanks in advance.
I’m afraid you cannot play the audio in WebView at background. Similar with Media Element, the audio is played by the app process, when the app is suspended (see App Life Cycle), it will stop playing the audio.
To play the audio at background in Windows Universal Apps, you need to use the BackgroundAudioPlayer, it will start a broker process and the audio will keep playing when the app process is suspended.
Related
My app is an audio streaming app and else has the audio background mode is enabled.
When the app is in background streaming audio and the network is dropping, my app finally goes in suspended state after less than about 30 secondes after the network dropped (the audio streaming buffer is empty and we don't more ear anything).
Is it something normal for an audio streaming application that is supposed to "live forever" ?
Is there a way to avoid this so that the application in background can detect when the network comes back and resume the audio player ?
Thank you a lot for your feedbacks and similar experiences.
I am building a iOS app with Ionic and Capacitor. I use AVFoundation inside a Capacitor plugin which provides a public method to play an audio file accessible at a remote URL. The basics work, the audio file is successfully played. Now I want to correctly handle interruptions and background audio. By background audio I mean start playing an audio file while the app is in the background and not continue playing it in the background when it was started in foreground before. To summarize, the app should behave the following way:
If another app (e.g. Spotify) is playing audio and my app wants to play audio, the other app should be interrupted and my app's audio should start playing without mixing.
If my app's audio is finished playing, the other app's audio should resume.
My app must be able to start playing audio without mixing when it is in the background.
I want to show a play/pause button and the audio title on the lockscreen and in the notification center.
I added the background mode audio capability. I use AVPlayer, AVAudioSession, MPNowPlayingInfoCenter and MPRemoteCommandCenter, followed best practices, especially regarding activation and deactivation of an audio session and interruption handling. I followed this question and this question. I tried several solutions, but never managed to achieve all of the above goals. What I found out so far is the following:
Goal 1. above is easy to achieve. Simply activate an audio session without mixing and start playing the audio.
After the audio of my app is finished, I deactivate the audio session. Unfortunately, I can only achieve goal 2. above if I don't use remote commands nor notification info. This means, my app then has no audio control UI on the lockscreen nor in the notification center. Somehow the configurations of MPNowPlayingInfoCenter and MPRemoteCommandCenter seem to affect the interruption behavior. As far as I could see, Apple documentation doesn't say anything about this.
I only manage to start playing audio in the background when setting the option .mixWithOthers. Apple documentation doesn't say anything about this, either.
Any help would be greatly appreciated.
Rony
When running my app in background, I would get MediaError.MEDIA_ERR_NONE_SUPPORTED (4) when trying to create and play an audio file.
While most suggestions for this error relates to file format, file existence or audio recording, my audio files were playing perfectly when the app was in foreground.
Note: I am already using the Cordova Background Mode plugin.
It turns out that the Cordova Music Controls is causing this interference.
Without manipulating the music controls, audio plays perfectly even when the app enters background.
The problem came from destroying the music controls, which makes iOS prevent your app from playing audio until the user resumes the app to foreground.
Turns out you don't have to destroy music controls before creating them again, to update the track label.
TLDR; Don't kill music controls while playing audio in the background.
Seems the default action for iOS 6 is to stop the video from playing after I switch to HOME screen. Then if I want to listen to the audio I have to go back to the app and press the 'Play' button again. I am using youtube API.
How can I continue playing the video when the application is in UIApplicationStateInactive and UIApplicationStateBackground. I just want to be able to listen to the audio even if I am on HOME screen or the screen is locked. Should I use a background thread or restart playing the video at the previous position as it was before turning the app inactive?
Take a look at the app 'Jasmine'. They managed to do something similar to what you are seeking. However, UIApplicationStateInactive/UIApplicationStateBackground will cause the video to pause. Double tapping the home button and then pressing the audio play button will cause the video's audio to resume without keeping the app active.
Take a look at the new iOS 7. You may have some luck there.
Inter-App Audio
Now your apps can make beautiful music together. With Inter-App Audio,
apps can register their audio streams to share with other apps. For
example, a series of apps could publish audio streams of instrument
tracks while another uses the combination of these streams to compose
a song. Inter-App Audio also provides for MIDI control of audio
rendering, remotely launching other registered Inter-App Audio apps
and more.
Some iOS apps like Pandora continue playing audio after the app screen has been exited, and even after the device has been locked.
Is it possible to keep audio playing in this way from a browser tab? In other words, can I code an HTML5 page that plays audio and continues playing even after the iPhone is locked?
Yes, audio playing in a mobile Safari tab will continuously play even when multi-tasking or locking your screen. However, if you save the bookmark to the home screen, open, play audio, and then hop out to multi-task, the audio fades out.
Not possible... the browser displaying your page controls what happens when it is deactivated (sent to the background). HTML5 won't touch the behavior of the underlying browser as it relates to system events, so the only way to control background activity in iOS is to write a native app.