Reputation: 791
I know similar questions have been asked, but mine is a slight variation on the others and I haven't been able to track down a solution on my own yet.
I have an app that blocks, on purpose, interface rotation throughout most of the app. However, the app does play videos and on that one view, rotation is allowed.
The app has been in the store for a while, functioning as intended, but I've received a couple of reports of the video not playing with devices running iOS 7 (the audio does play). The annoying part is I cannot replicate the issue (I've tested on a 4s, a 5 and a 5s). The video and audio works fine on all my devices.
On the "detail view" screen, there is a play button that will launch a segue to a new view which allows full screen video and rotation -
The "full screen video" screen is a UIViewController with an MPMoviePlayerController *moviePlayer and an (IBAction)playMovie; - the action is called automatically so that the video playback starts immediately when the new view appears.
viewDidLoad looks like
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[[self.detailItem valueForKey:@"exerciseVideo"] description] ofType:@"mov"]];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.moviePlayer.contentURL = url;
NSError *_error = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &_error];
[moviePlayer stop];
[moviePlayer setShouldAutoplay:NO];
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(playMovie)
userInfo:nil
repeats:NO];
and the playMovie action looks like
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerDidExitFullscreenNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
moviePlayer.allowsAirPlay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
Is there any reason that the video wouldn't play with that code? I'm wondering if it is setting related on an individual device (or maybe memory related if there are other background tasks), but I'm hitting my head against the wall here trying to troubleshoot an issue I can't replicate.
Any suggestions would be appreciated.
Upvotes: 1
Views: 628
Reputation: 27597
self.moviePlayer.contentURL
assignment schedueledTimer...
)viewDidAppear:....
self.playerInitialized
) that prevents restarting of the player once fullscreen is entered / left (as that will retrigger that appearance event
false
in viewDidLoad
viewDidAppear:...
, check if that flag is set to false
false
, run the player-init code from above from within viewDidAppear:...
true
false
within the player notification handler/s that signal aborted/finished playbackUpvotes: 1