Created
August 22, 2017 12:08
-
-
Save neonm3/06c3b5c911fdd3ca7c7800dccf7202ad to your computer and use it in GitHub Desktop.
gapless playback on IOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *videoLoopUrl; | |
// as [[NSBundle mainBundle] URLForResource:@"assets/yourVideo" withExtension:@"mp4"]]; | |
AVQueuePlayer *_loopVideoPlayer; | |
+(void) nextVideoInstance:(NSNotification*)notif | |
{ | |
AVPlayerItem *currItem = [AVPlayerItem playerItemWithURL: videoLoopUrl]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(nextVideoInstance:) | |
name:AVPlayerItemDidPlayToEndTimeNotification | |
object: currItem]; | |
[_loopVideoPlayer insertItem:currItem afterItem:nil]; | |
[_loopVideoPlayer advanceToNextItem]; | |
} | |
+(void) initVideoPlayer { | |
videoCopy1 = [AVPlayerItem playerItemWithURL: videoLoopUrl]; | |
videoCopy2 = [AVPlayerItem playerItemWithURL: videoLoopUrl]; | |
NSArray <AVPlayerItem *> *dummyArray = [NSArray arrayWithObjects: videoCopy1, videoCopy2, nil]; | |
_loopVideoPlayer = [AVQueuePlayer queuePlayerWithItems: dummyArray]; | |
[[NSNotificationCenter defaultCenter] addObserver: self | |
selector: @selector(nextVideoInstance:) | |
name: AVPlayerItemDidPlayToEndTimeNotification | |
object: videoCopy1]; | |
[[NSNotificationCenter defaultCenter] addObserver: self | |
selector: @selector(nextVideoInstance:) | |
name: AVPlayerItemDidPlayToEndTimeNotification | |
object: videoCopy2]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment