diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 0de7faaab..a6e64c590 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -7,6 +7,7 @@ // #import +#import #import "MWCommon.h" #import "MWPhotoBrowser.h" #import "MWPhotoBrowserPrivate.h" @@ -1110,8 +1111,8 @@ - (void)updateNavigation { // Disable action button if there is no image or it's a video MWPhoto *photo = [self photoAtIndex:_currentPageIndex]; if ([photo underlyingImage] == nil || ([photo respondsToSelector:@selector(isVideo)] && photo.isVideo)) { - _actionButton.enabled = NO; - _actionButton.tintColor = [UIColor clearColor]; // Tint to hide button + _actionButton.enabled = YES; +// _actionButton.tintColor = [UIColor clearColor]; // Tint to hide button } else { _actionButton.enabled = YES; _actionButton.tintColor = nil; @@ -1224,24 +1225,24 @@ - (void)playVideoAtIndex:(NSUInteger)index { - (void)_playVideo:(NSURL *)videoURL atPhotoIndex:(NSUInteger)index { // Setup player - _currentVideoPlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]; - [_currentVideoPlayerViewController.moviePlayer prepareToPlay]; - _currentVideoPlayerViewController.moviePlayer.shouldAutoplay = YES; - _currentVideoPlayerViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; + AVPlayer *player = [[AVPlayer alloc] initWithURL:videoURL]; + _currentVideoPlayerViewController = [[AVPlayerViewController alloc] init]; + _currentVideoPlayerViewController.player = player; _currentVideoPlayerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // Remove the movie player view controller from the "playback did finish" notification observers // Observe ourselves so we can get it to use the crossfade transition - [[NSNotificationCenter defaultCenter] removeObserver:_currentVideoPlayerViewController - name:MPMoviePlayerPlaybackDidFinishNotification - object:_currentVideoPlayerViewController.moviePlayer]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVPlayerItemDidPlayToEndTimeNotification + object:player.currentItem]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinishedCallback:) - name:MPMoviePlayerPlaybackDidFinishNotification - object:_currentVideoPlayerViewController.moviePlayer]; - + name:AVPlayerItemDidPlayToEndTimeNotification + object:player.currentItem]; // Show - [self presentViewController:_currentVideoPlayerViewController animated:YES completion:nil]; + [self presentViewController:_currentVideoPlayerViewController animated:YES completion:^{ + [_currentVideoPlayerViewController.player play]; + }]; } @@ -1249,8 +1250,8 @@ - (void)videoFinishedCallback:(NSNotification*)notification { // Remove observer [[NSNotificationCenter defaultCenter] removeObserver:self - name:MPMoviePlayerPlaybackDidFinishNotification - object:_currentVideoPlayerViewController.moviePlayer]; + name:AVPlayerItemDidPlayToEndTimeNotification + object:_currentVideoPlayerViewController.player.currentItem]; // Clear up [self clearCurrentVideo]; @@ -1269,7 +1270,7 @@ - (void)videoFinishedCallback:(NSNotification*)notification { } - (void)clearCurrentVideo { - [_currentVideoPlayerViewController.moviePlayer stop]; + [_currentVideoPlayerViewController.player pause]; [_currentVideoLoadingIndicator removeFromSuperview]; _currentVideoPlayerViewController = nil; _currentVideoLoadingIndicator = nil; diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index 5770d6787..0ded69996 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -11,6 +11,7 @@ #import #import "MWGridViewController.h" #import "MWZoomingScrollView.h" +#import // Declare private methods of browser @interface MWPhotoBrowser () { @@ -54,7 +55,7 @@ UIImage *_previousNavigationBarBackgroundImageLandscapePhone; // Video - MPMoviePlayerViewController *_currentVideoPlayerViewController; + AVPlayerViewController *_currentVideoPlayerViewController; NSUInteger _currentVideoIndex; UIActivityIndicatorView *_currentVideoLoadingIndicator;