0xced / XCDYouTubeKit

YouTube video player for iOS, tvOS and macOS
MIT License
2.92k stars 627 forks source link

Play the last played video from the stop time. #326

Closed akash-mastercreationz closed 7 years ago

akash-mastercreationz commented 7 years ago

Is there any way to save the songs played and whenever user play the same song, the song will start from the time it was stopped. Like in youtube .

SoneeJohn commented 7 years ago

@akash-mastercreationz you will need to save the time of the video (if you're using AVPlayer you can use the -currentTime method. Once you've saved this data somewhere, maybe in an NSMutableDictionary when the user plays the video, (again assuming that you're using AVPlayer use the -seek​To​Time: instance method.) Note, that you can only all this method if theAVPlayer status is equal to AVPlayer​Item​Status​Ready​To​Play

Also, technically this issue is outside of the scope of this library. 😉

SoneeJohn commented 7 years ago

@akash-mastercreationz here is a code snippet on how to use the seeking.

switch (self.playerView.player.currentItem.status) {
       case AVPlayerItemStatusReadyToPlay:
         [self.playerView.player seekToTime:CMTimeMake(50, 1.0) completionHandler:^(BOOL finished) {
                  [self.playerView.player play];
           }];
}
SoneeJohn commented 7 years ago

@akash-mastercreationz you will probably want to use KVO and observe the changes of the AVPlayerItem's status.

0xced commented 7 years ago

Closing this as a duplicate of #327.