i have add MPMoviePlayerController in my project in this way:
player = [[MPMoviePlayerController alloc] init];
[player setContentURL:videoURL];
[self.view addSubview:player.view];
then when i press a button i play the video:
[player play];
all works perfect, but when i press the button to enter in the fullscreen mode the video go in pause and i have to press the play button to continue the playback, anyone know why?
This worked well for me
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if (!self.moviePlayer.isFullscreen) {
[self.moviePlayer pause];
}
}
Related
I'm new in iPhone Application Development, and now i faced a problem, can any one tell me how can i play a video randomly without pressing the play button. The video should start automatically while the application launch and play randomly without stopping. I don't have any idea how to do this. I don't have any code also. Please help me any one...
Thanks in advanced.
You could implement it like this:
You need a movie player configured with e.g. a file url and add it to your view
NSURL *url = [[NSBundle mainBundle] URLForResource:movieName withExtension:#"mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = // set the frame
[self.view addSubview:moviePlayer.view];
Start the movie player
[moviePlayer play];
Listen to the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleMoviePlayerStatChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:moviePlayer];
Start the video again
- (void)handleMoviePlayerStatChange:(NSNotification *)note {
NSLog(#"mp playback state %i", moviePlayer.playbackState);
if (moviePlayer.playbackState == MPMoviePlaybackStatePaused) {
[moviePlayer play];
}
}
To hide the video controls set the controlStyle property of the movie player instance:
moviePlayer.controlStyle = MPMovieControlStyleNone;
I have a MPMoviePlayerController setup:
self.moviePlayerController = [[MPMoviePlayerController alloc] init];
[self.moviePlayerController.view setFrame:frame];
// hide controls initially
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:self.moviePlayerController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.
moviePlayerController];
Then when the notification is fired:
-(void)loadStateChanged:(NSNotification*)notification {
if (self.moviePlayerController.controlStyle == MPMovieControlStyleNone) {
[self.moviePlayerController setControlStyle:MPMovieControlStyleDefault];
}
}
On initial playback this works great, controls are not shown when playback starts but tapping the view shows the controls.
However, when a movie is already playing and I start playback of another URL, I hide the controls, but they reappear after playback starts of the second movie:
[self.moviePlayerController setContentURL:videoURL];
[self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
[self.moviePlayerController play];
The notification does fire again and it correctly has a controlStyle of MPMovieControlStyleNone which I then set to MPMovieControlStyleDefault.
Anybody have any experience with this, is there a way to make sure the controls stay hidden on a second playback, but are in fact visible when the user taps the movie view.
Thanks!
In my application i play video using mpmovieplayercontroller
first set scaling mode to MPmovieScalingmodefill and display video correct to scalingmode.
then after i view video in full screen and exit full screen then not set scaling mode to
MPmovieScalingmodeFill and display video in defualt mode.
below my code for video playing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(ExitFullScreen:)
name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[appDelegate.moviePlayerController setContentURL:fileURL];
if ([appDelegate checkDevice])
{
[appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,463)];
}
else
{
[appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,375)];
}
[appDelegate.moviePlayerController prepareToPlay];
appDelegate.moviePlayerController.scalingMode=MPMovieScalingModeFill;
appDelegate.moviePlayerController.controlStyle=MPMovieControlStyleDefault;
appDelegate.moviePlayerController.shouldAutoplay=NO;
[appDelegate.moviePlayerController setFullscreen:YES animated:YES];
[appDelegate.moviePlayerController play];
[self.view addSubview:appDelegate.moviePlayerController.view];
- (void)ExitFullScreen:(NSNotification *)notification{
NSLog(#"Exit full Screen");
[appDelegate.moviePlayerController setControlStyle:MPMovieControlStyleEmbedded];
[appDelegate.moviePlayerController setScalingMode:MPMovieScalingModeFill];}
so my probleem is how can set scaling mode after exit full screen or do not change scaling mode after exit screen ?
please help me out.
thanks.
This isn't the "ideal" solution, but it works!
Basically, once you exit full screen the MPMoviePlayerController instance gets all screwed up and resetting the scaling property to MPMovieScalingModeFill won't help no matter where or when you do it (I've tried all sorts of stuff and after an hour gave up). Easiest solution is to remove the MPMoviePlayerController and simply allocate a new instance of MPMoviePlayerController each time full screen is exited (not ideal, but totally works):
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:NO];
if (self.moviePlayer != nil)
[self.moviePlayer.view removeFromSuperview];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
self.moviePlayer.view.frame = CGRectMake(#, #, #, #);
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.shouldAutoplay = NO;
[self.moviePlayer setContentURL:self.videoURL];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setScalingMode:MPMovieScalingModeFill];
[self.view addSubview:self.moviePlayer.view];
}
PS: Don't forget to call super's viewDidAppear or suffer all sorts of unforeseeable mayhem (a very common mistake in iOS development)
I believe this will generate the MPMoviePlayerScalingModeDidChangeNotification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieScalingModeDidChange:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:nil];
MPMoviePlayerScalingModeDidChangeNotification
Posted when the scaling mode of a movie player has changed. There is no userInfo dictionary. Scaling mode can change programmatically or by user interaction. To set or retrieve the scaling mode of a movie player, access its scalingMode property. The movie player whose state has changed is available as the object associated with the notification.
How can I play a video in fullscreen, preventing the controls to appear when touching video (pause, play, etc)? Instead, when video is touched, I want to close it.
Can this be done?
Thanks in advance
MPMoviePlayerViewController *playerViewController=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"xyz" ofType:#"mp4"]]];
[self presentModalViewController:playerViewController animated:YES];
MpMoviePlayerController *player = [playerViewController moviePlayer];
player.controlStyle=MPMovieControlStyleNone; //hide the controls
[player play];
I am adding an MPMoviePlayerController to a view like so:
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.controlStyle = MPMovieControlStyleNone;
[player.view setFrame:self.playerView.bounds];
[self.playerView addSubview:player.view];
self.playerView is a small view inside my main view and I have custom buttons that control playback within that same main view. This all works fine.
I have a fullscreen button that works like so:
- (IBAction) btnFullScreenPressed:(id)sender {
[player setFullscreen:TRUE animated:TRUE];
[player setControlStyle:MPMovieControlStyleFullscreen];
}
This works fine, but then when I hit the Done button on the full screen controls, the movie stops playing but does not return to the smaller self.playerView in my view. How can I get it to "un-fullscreen" and return to the smaller self.playerView?
Thanks.
Quite unintuitively you actually have to set the control style to default, i.e.:
- (IBAction) btnFullScreenPressed:(id)sender {
[player setFullscreen:TRUE animated:TRUE];
[player setControlStyle:MPMovieControlStyleDefault];
}
and, of course, then set it back to none when you receive MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification (I prefer "did exit").