iOS Question AVPlayerViewController (iUI8) - Background play

Pendrush

Well-Known Member
Licensed User
Longtime User
Is this: https://www.b4x.com/android/forum/threads/background-playback.49337/#content still valid method for background play with AVPlayerViewController?
I have a lot reports that app stop to play music on iPhone 6 and above with iOS 11, working fine on iPhone 5s with iOS 11, also working fine on devices with iOS 10 and below. There is no crash report (I have local Mac with latest xCode v9.2), it's look like system kill app after approx 10 minutes, when screen is off. When music stop and user click on app icon or select app from recent app list, application start loading procedure, so I'm almost sure system killed app in background. I'm also unable to reproduce same behavior with Simulator.
Anyone have solution?

PS.
This app is over 2 years old, there is no problem before with lower iOS versions and VideoView.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
I also need events and option to change stream without creating hundreds of players.
Only problem I have is background mode.
How to tell system "don't kill app" in proper way?

Edit:
From documentation:
When the UIBackgroundModes key contains the audio value, the system’s media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content or recording audio content, the app continues to run in the background. However, if recording or playback stops, the system suspends the app.
https://developer.apple.com/library....html#//apple_ref/doc/uid/TP40007072-CH4-SW26

It's look like somehow system don't detect player is playing music for some reason.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've updated the code in that example.
The changes are:
B4X:
success = [audioSession setPreferredSampleRate:4096 error:nil];
   [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Source: https://stackoverflow.com/a/29140493/971547

Tested on iPhone 8. It plays for 20 minutes now.
 
Upvote 0
Top