"Done" button in MPMoviePlayerController doesn't work when full screen mode - ios

Well, I could find many questions about the same or similar questions and answers... However, nothing could help me. Only when I don't use the property "controlStyle" as "MPMovieControlStyleFullscreen", "done" button works. I tried this way..
MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mpMoviePlayerController.controlStyle = MPMovieControlStyleNone;
[mpMoviePlayerController setUseApplicationAudioSession:NO];
[mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
[mpMoviePlayerController setFullscreen:YES animated:YES];
[mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];
[[globalSingleton paintingView] addSubview:mpMoviePlayerController.view];
[mpMoviePlayerController prepareToPlay];
[mpMoviePlayerController play];
mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
or this way..
MPMoviePlayerController *mp;
MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mp = [mpVC moviePlayer];
mp.controlStyle = MPMovieControlStyleFullscreen;
mp.fullscreen = NO;
mp.useApplicationAudioSession = NO;
mp.view.frame = CGRectMake(0, 0, 1024, 768);
[[globalSingleton paintingView] addSubview:mp.view];
([globalSingleton paintingView] is just for representing main view. I already checked there's no problem on it.)
Please share what u know about this problem. Thx in advance!

Based on your code, It looks to me that your intention is to just have a fullscreen movie player take over the screen. In that case, you're probably better off using the MPMoviePlayerViewController, but you need to present it as a modal view controller using your current view controller like this:
MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL];
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
// Self is the UIViewController you are presenting the movie player from.
[self presentMoviePlayerViewControllerAnimated:movieViewController];
The "Done" button should work properly in this case, and dismiss the modal MPMoviePlayerViewController
On the other hand, If you're more interested in animating the movie from where you've added it in the current view hierarchy, here is an example of what I have done to achieve this:
I also found that setting the MPMoviePlayerController's controlStyle property to MPMovieControlStyleFullscreen had the same result–the "Done" button did not close the MPMoviePlayerController. When I changed it to MPMovieControlStyleDefault, it worked as expected. However, in my case, I'm adding the MPMoviePlayerController's view as a thumbnail-sized subview to the currently displayed UIViewController's view. I initially have the MPMoviePlayerController's controlStyle set to MPMovieControlStyleNone. I have a custom UIButton on top of the thumbnail-sized movie player view, and in the button's action method, I'm changing the controlStyle of the MPMoviePlayerController to MPMovieControlStyleDefault, then calling setFullscreen:animated: which animates the movie player view into fullscreen mode. Then, tapping the "done" button properly animates the player back into place in the thumbnail-sized subview of my UIViewController's view. Here is an example:
Initial instantiation of my MPMoviePlayerController:
// My moviePlayerController is a property
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = NO;
// Add the moviePlayer's view as a subview of a my UIViewController's view.
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90);
[self.view addSubview:moviePlayer.view];
Note: I also added a custom UIButton (to invoke fullscreen playback) on top of my moviePlayer's view and set it's action to call the following method:
- (void)buttonAction:(UIButton *)sender
{
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
}
Note: I also observe and handle the MPMoviePlayerWillExitFullscreenNotification where I set the controlStyle back to MPMovieControlStyleNone.

Related

How do I add a volume control in my MPMoviePlayerController instance

The below is the code which opens a video on a button press. Everything is fine but I want to add a volume control for my video player. Is there a default feature from the MPMoviePlayerController that I can just enable, or do I have to use the slider from the objects library , drag and drop it, and the adjust the volume according to the slider value?
NSString *url = [[NSBundle mainBundle] pathForResource:#"space-time" ofType:#"mp4"];
moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
[moviePlayer play];
to add a volume view use this code
make a uiview in your viewcontroller of about 200width by 30height,
drop outlet for that view (view1) after that
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:self.view1.bounds] ;
[self.view1 addSubview:volumeView];
volume slider will show up in that view1

how to show MPMoviePlayer done button when video is playing?

I want to play video in MPMoviePlayerViewController, it works fine and plays video but problem is that it does not show done button unless i switch to the full screen mode. It should automatically show player along with done button as shown in attached screen.
here is the code:
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[self presentMoviePlayerViewControllerAnimated:mp];
Done button will be visible only when video is played in full screen mode. So, either you need to play the video in full screen mode using the following code:
player.moviePlayer.fullscreen = YES;
Or you need to customise the control to add your own Done button.
Done button visible you set the ControlStyle.
[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[player.moviePlayer setFullscreen:NO animated:YES];

ios6 moviePlayer first frame not appearing upon creation

I have methods inside my open class controller that instantiates a moviePlayer, which is set to 'autoPlay = NO';
I have added the movieplayer.view as a subview of the controllers view, configured it and created a full screen button on top for starting the video. Since iOS4.3, this has been working fine. The button is transparent and the first frame of the video showed through ( which was a picture of a custom Automoble Auto-Start button).
Since iOS6, I only get a black screen.
Clicking the image-button does start the video as it should; calls [moviePlayer play]
Has something changed that I have not taken into consideration?
I have provided the two sections of code I think are necessary.
#define INTRO_MOVIE #"Intro.mov"
-(void)viewDidLoad
{
if(SHOULD_PLAY_INTRO_VIDEO)//Debug switch to ignore the intro video
{
// Prepare the movie and player
[self configureIntroMoviePlayer];
[self.view addSubview:moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];
// Add and Show the Start Button to start the App
[self configureStartButton];
[self.view addSubview:startButton];
}
}
-(void)configureIntroMoviePlayer
{
LOGINFO
// Prepare the Intro Video
NSString *pathToIntroVideo = [ mainFilePath_ stringByAppendingPathComponent: INTRO_MOVIE];
NSURL *URLToIntroVideo = [NSURL fileURLWithPath:pathToIntroVideo];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:URLToIntroVideo];
[moviePlayer setShouldAutoplay:NO];
moviePlayer.view.frame = CGRectMake(0, -20, 1024, 768);
[moviePlayer setControlStyle:MPMovieControlStyleNone];
//fixing video brightness Difference with iPad2
if(isIpad2)
{
moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
moviePlayer.view.alpha = .99;
}
// Create the sKip button for cancelling the Intro Video
skipIntro = [UIButton buttonWithType:UIButtonTypeCustom];
[skipIntro showsTouchWhenHighlighted];
skipIntro.frame = CGRectMake(900, 20, 111, 57);
[skipIntro addTarget:self action:#selector(skipIntroWasPressed) forControlEvents:UIControlEventTouchUpInside];
}
I am not sure why I got a -1 rating for this question for lack of research or clarity?
Maybe I do not know the proper usage of this forum.
I apologize.
I did find that adding [moviePlayer prepareToPlay] solved the problem. Like I said, it was odd that the first frame always showed up prior to iOS 6.
Have you tried:
[moviePlayer.view addSubView:startButton];

Play Video as the Background on iPhone on button click?

I want to create an app which has a default image as the background of a view that has many buttons on it. When a user clicks on any of the buttons, a unique video plays. The buttons are gonna be almost transparent so, I want the video to play in the background of the same view itself (replacing/playing above the image) and not open in a new Player(as it does using the media player). Has anyone tried it, or does anyone have any idea?
Thank You!
#import <MediaPlayer/MPMoviePlayerController.h>
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: moviePath]];
moviePlayer.controlStyle = MPMovieControlStyleNone;
[RootViewController.view insertSubview: moviePlayer.view aboveSubview: myView];
[moviePlayer play];

MPMoviePlayerController stops and resets the movie when user tries to play fullscreen [iOS]

I embedded a MPMoviePlayerController on my mail view. I can play/pause the movie and seek forward/backward. But when I touch the "fullscreen button" the movie stops and the playback state is set to MPMoviePlaybackStateStopped... Should the movie be played in full screen?
Here is my code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
player.shouldAutoplay = NO;
player.movieSourceType = MPMovieSourceTypeFile;
player.controlStyle = MPMovieControlStyleEmbedded;
player.allowsAirPlay = YES;
player.view.frame = CGRectMake(xPos, yPos, width, height);
[self.view addSubview:player.view];
I found my bug: when pressing the full screen toggle button in MPMoviePlayerController's view, the method "viewWillLayoutSubviews" is invoked. I could never imagine this behavior...
I hope my experience can be useful to other developers.
Remember that any containing ViewController will have its viewWillDisappear, viewDidDisappear methods invoked when the MPMoviePlayerController goes full screen. Also, viewWillAppear and viewWillDisappear get called when it comes back from full screen.
If you have any logic in there that affects video playback behavior, it'll get called unless you use some conditional logic to see if the video is still playing.

Resources