AVPlayer Pause and play issues when app goes background

前端 未结 2 502
广开言路
广开言路 2021-02-09 12:56

It\'s working correctly if the app just become inactive/active (when some alert came or by double clicking on home button)

AVPlayer *player;

- (void)application         


        
2条回答
  •  独厮守ぢ
    2021-02-09 13:51

    Follow below steps:

    1) Firstly add float *time in appDelegate.h file.

    2) Take current time in applicationWillResignActive

    3) Add below methods

    ApplicationWillResignActive method pause player and save current time of player

    - (void)applicationWillResignActive:(UIApplication *)application
    {
       [player pause];
       time = player.currentTime
    }
    

    Now in applicationDidBecomeActive add seekToTime

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
      [player seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
      [player play];
    }
    

提交回复
热议问题