AvPlayer Suspends and reproduces problems when the application enters the background

It works correctly if the application just becomes inactive / active (when there is a warning or by double-clicking on the home button)

AVPlayer * player;

- (void)applicationWillResignActive:(UIApplication *)application { [player pause]; } - (void)applicationDidBecomeActive:(UIApplication *)application { [player play]; } 

If the application enters the background mode (by pressing the "home" button) and returns, it does not play from the paused position, but does not play from another point (sometimes from the beginning, sometimes from the middle). What could be the problem?

+4
source share
2 answers

Follow the instructions below:

1) First add float *time to the appDelegate.h file.

2) Take the current time in applicationWillResignActive

3) Add below methods

applicationWillResignActive player pause and save player current time

 - (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]; } 
+18
source

You must call these methods before the application comes to the background. [player pause]; or [player stop];

0
source

Source: https://habr.com/ru/post/1442916/


All Articles