Search code examples
iosobjective-cavplayer

iOS AVPlayer Entering the foreground will play automatically


I use AVPlayer to play video.I haven't added any NSNotifications yet. When the app goes into the background, video will pause, which is what I expected. But when the app goes back to the foreground, video will play again. And I'm going to pause video, and then I'm going to go back in the background, and then I'm going to go back to the foreground, and video is going to play again. Why is that? 1. Why does video automatically play when it enters the foreground from the background? I didn't do anything... 2. What should I do? Getting video from the background into the foreground does not play automatically


Solution

  • use the below fun to make the video pause when going into background.

    func applicationWillResignActive(_ application: UIApplication)