Play Video in Background using Avplayer

后端 未结 5 2269
一个人的身影
一个人的身影 2020-12-01 04:16

In my iPhone application I want to keep play video when application enter in background mode.

I am using AVPlayer and not finding any way to play video in background

5条回答
  •  悲哀的现实
    2020-12-01 04:39

    The above answers pause the video for a second when the app enters background, but by using the method mentioned below it keeps the video playing while app goes to background without any glitch.

    If the AVPlayer's current item is displaying video on the device's display, playback of the AVPlayer is automatically paused when the app is sent to the background. There are two ways to prevent this pause:

    1. Disable the video tracks in the player item (file-based content only).
    2. Remove the AVPlayerLayer from its associated AVPlayer (set the AVPlayerLayer player property to nil).

    REFERENCE

    Playing media while in the background using AV Foundation on iOS

提交回复
热议问题