Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed depricated mediaplayer #658

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Pod/Classes/MWPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <QuartzCore/QuartzCore.h>
#import <AVKit/AVKit.h>
#import "MWCommon.h"
#import "MWPhotoBrowser.h"
#import "MWPhotoBrowserPrivate.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1224,33 +1225,33 @@ - (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];
}];

}

- (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];
Expand All @@ -1269,7 +1270,7 @@ - (void)videoFinishedCallback:(NSNotification*)notification {
}

- (void)clearCurrentVideo {
[_currentVideoPlayerViewController.moviePlayer stop];
[_currentVideoPlayerViewController.player pause];
[_currentVideoLoadingIndicator removeFromSuperview];
_currentVideoPlayerViewController = nil;
_currentVideoLoadingIndicator = nil;
Expand Down
3 changes: 2 additions & 1 deletion Pod/Classes/MWPhotoBrowserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <MediaPlayer/MediaPlayer.h>
#import "MWGridViewController.h"
#import "MWZoomingScrollView.h"
#import <AVKit/AVKit.h>

// Declare private methods of browser
@interface MWPhotoBrowser () {
Expand Down Expand Up @@ -54,7 +55,7 @@
UIImage *_previousNavigationBarBackgroundImageLandscapePhone;

// Video
MPMoviePlayerViewController *_currentVideoPlayerViewController;
AVPlayerViewController *_currentVideoPlayerViewController;
NSUInteger _currentVideoIndex;
UIActivityIndicatorView *_currentVideoLoadingIndicator;

Expand Down