MPMoviePlayerController black screen when app enter foreground from background - iphone

I'm using an MPMoviePlayerController for playing video in my iPhone app.
When MPMoviePlayerController is playing, press home button on iPhone, make the app enter background.
Then tap the app's icon to make the app enter foreground, the MPMoviePlayerController's view will be black screen for a short time, about 1 to 15 seconds.
How to make the MPMoviePlayerController's video shows immediately when app came to foreground?
Special thx! :D

NSURL *movieURL = [NSURL URLWithString:#"http://......"];
// Initialize a movie player object with the specified URL
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self.moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer play];
I Hope this will help You.

Related

iOS 6.0 MPMoviePlayerController full screen mode black color? then App blocked no more actions

MPMoviePlayerController video goes to full screen mode at the time screen is black color. And then the app was blocked. This issue only for iOS 6.0. But iOS 5.1 working fine. This is my code. IF I double click the player full screen is opened, But show black screen.
self.moviePlayerController = [[MPMoviePlayerController alloc] init];
[self.moviePlayerController.view setFrame:_moviePlayerContentView.bounds];
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
[self.moviePlayerController setAllowsAirPlay:NO];
[_moviePlayerContentView addSubview:self.moviePlayerController.view];
[self.moviePlayerController stop];
[self.moviePlayerController setContentURL:videoURL];
[self.moviePlayerController.view setHidden:NO];
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController play];
How can I handle this issue?
After reach MPMovieFinishReasonPlaybackEnded, then How to disable the full screen mode?
Please help me. Thanks in advance.
In iOS 6,MPMoviePlayerController full screen calls ViewDidDisappear method. You may have stop player in ViewDidDisappear method. If so, remove it for while and try once again.

Play a video from a server without exiting the app - Cocoa Touch, iPhone

Basically I have 8 thumbnails which are buttons. When each button is tapped, it launches the video which is located on my server. However at the moment, when a thumbnail is tapped, the video launches in safari and exits the app. I want it so the video launches in the app instead of exiting it, so once the user has finished watching the video, they are then returned to the app.
Here is the code I've used.
-(IBAction)goAbv1:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://mywebsite.com/video.mp4"]];
}
Try this if you are on iOS 3.2+
NSString *videoURLString = #"http://MypathtoIphoneCompatibleVideoMp4";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentMoviePlayerViewControllerAnimated will handle the modalviewcontroller and put it on top of the stack automatically so the video can be played. This should work easily.

Getting a black screen when trying to play a movie

When i'm trying to play a movie on my iPhone, it isn't work. I dont know why.. searched here and all over the internet, try 5 different codes, but still can't get it to work. I'm new to Obj-C, so please be patient.
I just want the movie to play and when the movie is done, to exit the player. also, at the beginning I dont want it to show a black screen, I want to see the first frame of the video instead. is it possible?
-(void)playTheMovie
{
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"C061381" ofType:#"mp4" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
}
Thanks!
Most probably you are messing up with the URL.
Check out Movie player sample project from apple
https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
Run it first to confirm its functionality and then
Replace its movie with yours and change the extension and path name in the code
if it works copy the code to your project..

MediaPlayerViewController rotates into view before play

My MediaPlayerViewController developed this funny thing of rotating into view! My whole app is landscape based, but the MediaPlayerViewController seems to rotate from portrait to landscape and when finished the previous view would then also rotate from portrait into its original landscape orientation. This will not happen in a small test app. Only when the app becomes complicated. I have tried preloading the movie, doesn't help, i have tried didRotatefromInterfaceOrientation, nothing. I have my supported orientations set and to return UIInterfaceOrientationIsLandscape. My code for the movie if that might help:
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"BearA-least" ofType:#"mov"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentModalViewController:moviePlayer animated:NO];
moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer.moviePlayer play];
I'm new to developing and have been struggling with this problem for a while. Any input would be greatly appreciated. I've seen people having similar problems with views rotating.
As I see, you're using MediaPlayerViewController and presenting it using presentModalViewController
MoviePlayerViewControllers are usually displayed using [self presentMoviePlayerViewControllerAnimated:(PlayerViewController)]
As I can see, you're preventing your user from controlling the playback -> MPMovieControlStyleNone
Hint: You might also want to set the movieSourceType property on your MoviePlayerController.
For controlling the orientation in a way as you're trying to achieve, I would suggest you to subclass MPMoviePlayerViewController and listen for notifications sent by the MPMoviePlayer on the various movie playback events.

MPMoviePlayerController for iPhone App on iPad

For some reason, the expand button the arrow points to in the screenshot below causes the view controller that initiated video playback to animate back over top of the video, but without stopping video playback which means you can still hear the audio even though the video is no longer visible. I've tried other movie control styles, but there are other problems with those (for example, no controls causes the player to play the entire video before dismissing, i.e. no 'Done' button).
Here is the code that initiates the video playback:
player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[player setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:player animated:YES];
[[player moviePlayer] play];
Any ideas/suggestions as to how I can either disable that button or receive its notification so I can respond accordingly?
Thanks.
I can't find a solution to this, but I did find a workaround. I simply call [player stop]; in my -viewDidLoad of the calling view controller. The outcome won't be what the user expects when they press that button, but it's better than allowing the video to continue to play when they press it.