Is it possible to play video using Avplayer in Background?

前端 未结 8 1360
清歌不尽
清歌不尽 2020-12-04 20:19

I am using Avplayer to show video clips and when i go back (app in background) video stop. How can i keep playing the video?

I have search about background task &am

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 20:54

    I'd like to add something that for some reason ended up being the culprit for me. I had used AVPlayer and background play for a long time without problems, but this one time I just couldn't get it to work.

    I found out that when you go background, the rate property of the AVPlayer sometimes seems to dip to 0.0 (i.e. paused), and for that reason we simply need to KVO check the rate property at all times, or at least when we go to background. If the rate dips below 0.0 and we can assume that the user wants to play (i.e. the user did not deliberately tap pause in remote controls, the movie ended, etc) we need to call .play() on the AVPlayer again.

    AFAIK there is no other toggle on the AVPlayer to keep it from pausing itself when app goes to background.

提交回复
热议问题