MPMoviePlayerViewController Hide Status Bar - ipad

I have an iPad application that creates and shows a video with an MPMoviePlayerViewController. Here's my code:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:URLEncode(uri)]];
[mpvc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[mpvc setWantsFullScreenLayout:YES];
[<MainViewController> presentModalViewController:mpvc animated:YES];
Movie load/playback works fine, however, when the Movie Controller appears, it shows the status bar (connection, battery, hour) at the top, even when I have it deactivated on my main window.
I've tried doing:
[mpvc setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And nothing seems to work, HOWEVER if I also put:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
The status bar disappears! But the Movie Controller still gets resized as if the status bar is there (even when I already used -setWantsFullScreenLayout:).
Can someone point me to an easy (proven) way to show the video without the status bar?
Thanks.

Just realised the question was iPad-specific. My code was for the iPhone, but some of it may help you anyway.
I had to do this a couple days ago, I think your issue is simply not calling hide on the status bar after the video starts playing. Either way I have the tried and tested code here which works from 3.0 to 4.2:
- (IBAction) playIntroVideo
{
NSString *videoString = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
if
(
[_player respondsToSelector:#selector(view)] &&
[_player respondsToSelector:#selector(setFullscreen:animated:)] &&
[_player respondsToSelector:#selector(setControlStyle:)]
)
{
[[_player view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT_FULL)];
[_player setFullscreen:YES animated:YES];
[_player setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:[_player view]];
}
[_player play];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(terminateVideo)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden = YES;
}
- (void) terminateVideo
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden = NO;
if ([_player respondsToSelector:#selector(view)])
{
[[_player view] removeFromSuperview];
}
_player = nil;
[_player release];
}

The answer to this question has an error at the end:
_player = nil;
[_player release];
These should be reversed:
[_player release];
_player = nil;
Messaging nil with release has no effect.

You can set UIStatusBarHidden in your plist, that should solve it :)

Related

How to set userinteractionEnabled: to NO for an AVPlayerViewController?

I try to set userinteractionEnabled: to NO for an AVPlayerViewController
[playerViewController setUserInteractionEnabled:NO];
but I have an error
"No visible #interface for 'AVPlayerViewController' declares the selector 'setUserInteractionEnabled:'"
No visible #interface
Here is my complete code:
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
playerViewController.showsPlaybackControls = false;
[playerViewController.player play];
[playerViewController setUserInteractionEnabled:NO];
[self.navigationController pushViewController:playerViewController animated:YES];
[self performSelector:#selector(popToMain) withObject:nil afterDelay:durationInSeconds];
I just would like the people cannot click on the screen during the video.
Thanks in advance.
Maybe this might help you:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
Try this:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
or this:
playerViewController.view.userInteractionEnabled = NO;

MPMoviePlayerController gives me a black empty view on BACK button

I have used MPMoviePlayerController to play video in my web view from a live url
but when i pop the view controller so at that time the black screen appears in the view and the navigation bar title changes as it should be.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *movieURL = [NSURL URLWithString:self.url];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.contentURL = movieURL;
if (self.moviePlayer)
{
[self.moviePlayer prepareToPlay];
self.moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
// save the movie player object
[self.moviePlayer setFullscreen:YES];
[self.moviePlayer setShouldAutoplay:YES];
[self.moviePlayer setAllowsAirPlay:YES];
// Play the movie!
[self.moviePlayer play];
[self initializeNavigationController];
}
}
-(void)initializeNavigationController
{
UIBarButtonItem *buttonBack = [[UIBarButtonItem alloc] backButtonWithtarget:self action:#selector(Back)];
self.navigationItem.leftBarButtonItem = buttonBack;
}
-(void)Back
{
[self.moviePlayer.view removeFromSuperview];
[self stopLoadingVideoInView];
[self.navigationController popToRootViewControllerAnimated:YES];
}
Live video screen
After Back button press
I think you just remove [self.view removeFromSuperview]; and replace with
[self.moviePlayer.view removeFromSuperview];
I solved it finally
In app delgate i created a method to allocate memory to vc again
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}
and on my back button action
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.resetAppToFirstController;
This solved my issue it may help some one for MPMoviePlayer
In case you are added youMovieController as sub view of parent view, use this method to remove it.
[self.view removeFromSuperView]
In case you are pushing viewController via UINavigationController, just call this to go back.
[self.navigationCotroller popViewController:animated]
In case you are present ViewController, use this to remove it.
[self dismissViewController]
remove [self.view removeFromSuperview]; and replace with [self.moviePlayer.view removeFromSuperview];
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}

MPMoviePlayerController Won't Play Video

The following MPMoviePlayerController will not present in my iOS application.
I am trying to make it appear when my tableView row is selected:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:videoUrl]];
[player setFullscreen:YES];
[player play];
[self.tableView addSubview:player.view];
}
Any ideas?
Instead try:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoUrl]];
[player prepareToPlay];
[self presentViewController:player animated:YES completion:nil];
I wouldn't add the view as a subview of a table view if I were you.
You have forgotten to give player.view a size.
You have forgotten to say prepareToPlay to the player. An MPMoviePlayerController absolutely will not play until you have done that.

How can I play movies on the toppest screen in IOS?

I am trying to play movies from a view controller. I am using the code below to do that:
VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];
Normally it works fine. But sometimes, movie starts but I cannot see the video, just I can hear the sounds.
What is the best way to play video on top of everything?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Another solution would be to segue to another ViewController and dissmiss it when the movie ends.
You can also try using AVPlayer. In that case, you can play the video in your current view itself without having a separate overlay for the video.
Here's an example of playing multiple AVPlayers. You can modify the code to play a single video.

MPMoviePlayer - black screen - iOS 5 - no video playing

In iOS 4 this Code worked to play a movie:
-(IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"testbild1" ofType:#"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
//[self.view addSubview:moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
//[moviePlayerController release];
}
Now, I only get a blackscreen. No controls, nothing. Video path is correct, I tested that. If I add just a white Subview by button click, it works. So the method is called.
Thanks in advance!
I have solved the issue by putting in the .h file
MPMoviePlayerController *moviePlayer;
iOS 5 with ARC works differently than iOS 4.
The .m file must be:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
If you are on iOS 5.0 or 5.1, check your moviePlyer has a setting like below.
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
If so, when you set [moviePlayer setFullScreen:YES animated:YES];
then MPMoviePlayerPlaybackDidFinishNotification notification will be called instead of being called MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification

Resources