简体   繁体   中英

Keep audio and remove video stream for AVPlayer when app goes into background

I would like to reduce the bandwidth my app consumes when the user plays a video and goes into background mode (using a HLS stream). I want the audio to still play but it seems like the AVPlayer keeps downloading the video segments even though they should not be needed (user can't see anything anyway).

Theoretically, I could have a video with a very low bitrate (such as a black screen) and set player.currentItem.preferredPeakBitRate = 1 when the app enters background mode, but then I don't know how to prevent the app from downloading a huge number of black video segments in background, so that when the user returns, he/she gets a black screen for a long time. Also, it is unclear how I can prevent the black screen from showing in foreground mode if the user has a bad connection?

I have also tried to disable the video through the AVURLAsset's - (AVMediaSelectionGroup *)mediaSelectionGroupForMediaCharacteristic:(NSString *)mediaCharacteristic . I could do this for audio, but not for video, since the method returns nil for the parameter AVMediaCharacteristicVisual . Is it something I can change in my HLS manifest to enable this?

The best way to handle this is to use an incoming audio profile through the manifest and not doing much for this on the client end. This is because the audio only profile will have comparatively lower bitrate than to audio+video profiles and if you put the condition to check - if indicatedbitrate less than the minimum audio+video profile the manifest has, it will automatically switch to the audio profile when it requires.

You would also need to add the observer for AVPlayerItemNewAccessLogEntry .

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