how to show MPMoviePlayer done button when video is playing? - ios

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];

Related

Why isn't the scalingMode of my MPMoviePlayerController being respected when coming back from Full Screen?

I have an instance of MPMoviePlayerController that is correctly displaying a HLS video stream on Portrait mode and also on Full Screen when I rotate my iPhone to the Landscape mode for the first time. The issue happens when I come back from Full Screen: the scalingMode property of my MPMoviePlayerController is still set to MPMovieScalingModeAspectFill but the video is displayed as it is set to MPMovieScalingModeAspectFit.
Before adding its view as a Subview (self.moviePlayer.view) of my View (self.movieView) I set its scalingMode to MPMovieScalingModeAspectFill and everything works fine untill I exit Full Screen.
- (void) play
{
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidStart:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.moviePlayer.contentURL = videoURL;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.shouldAutoplay = YES;
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
NSLog(#"%ld", (long) self.moviePlayer.scalingMode);
self.moviePlayer.view.frame = CGRectMake(0, 0, 320, 180);
[self.movieView addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:NO animated:NO];
}
When I return from Full Screen it is set to the default value (MPMovieScalingModeAspectFit) and I can't change it back to MPMovieScalingModeAspectFill even if I explicity try to when I receive the MPMoviePlayerScalingModeDidChangeNotification.
- (void)movieScalingModeDidChange:(NSNotification *)notification
{
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
NSLog(#"%ld", (long) self.moviePlayer.scalingMode);
}
The weird thing is that that this NSLog gives me:
-[CameraViewController play]:2
Which according to the Documentation is the enum for MPMovieScalinModeAspectFill, but the video is not it this aspect mode.
typedef enum {
MPMovieScalingModeNone,
MPMovieScalingModeAspectFit,
MPMovieScalingModeAspectFill,
MPMovieScalingModeFill
} MPMovieScalingMode;
Has anyone experienced this same issue? Thanks in advance!
You need change scalingMode to any value other than MPMovieScalingModeAspectFill and set aspect fit again on receiving MPMoviePlayerScalingModeDidChangeNotification
- (void)playerDidExitFullscreen:(NSNotification *)notification
{
self.moviePlayer.scalingMode = MPMovieScalingModeNone;
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}
It works with tiny animation issue.
From what I have seen in a couple of other questions here and here it really seems that MPMoviePlayerController gets screwed when it comes back from full screen and the workaround is to remove its element from the view and add it back again using the desired scalingMode. Well, I don't want my stream to be reloaded since buffering might take too long sometimes and this really kills the user experience.
So here is what I did. I set the scalingMode to its default value when the view is loaded and added a "resize" button that changes this property when the user clicks it (I remembered some users saying that we were "leaving out" important parts of the image on the mobile). Now when the user rotates its iPhone it will remaing with the desired scalingMode and when it returns to the Portrait mode, it will be set as the default.
I hope this may be of help to anyone facing the same issue.

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

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.

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.

MPMoviePlayerController control visible when starting movie

I have strange problem with MPMoviePlayerController. When movie starts , top bar with done button & controls remain visible for few seconds.Then disappears.
I am using
[player setControlStyle:MPMovieControlStyleFullscreen];
[player setFullscreen:YES];
player is an object of MPMoviePlayerController
I just want movie to play in full screen with top bar & controls hidden
& become visible only if user taps the screen
I am using iOS 4.0
try this
before starting the video
player.controlStyle = MPMovieControlStyleNone;
and when movie starts playing then set
player.controlStyle = MPMovieControlStyleFullscreen;
You can get play callback from MPMediaPlayback protocol.

Resources