MPMoviePlayerControler fullscreen problem if opened on PresentModalViewController in iPad - ipad

I have a problem opening a MPMoviePlayerController in fullscreen mode starting from a presentModalViewController.
I open a presentModalViewController
//Create controller
mDetailFilmController = [[DetailFilmController alloc]
initWithNibName:#"DetailFilmController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:mDetailFilmController];
//Set modal style
navController.modalPresentationStyle = UIModalPresentationPageSheet;
navController.navigationBar.barStyle = UIBarStyleBlack;
//presentModalViewController
[self presentModalViewController:navController animated:YES];
//Dimension
navController.view.superview.bounds = CGRectMake(0, 0, 700, 700);
in DetailFilmController there's a MPMoviePlayerController and this is the code for play button:
self.mPlayer = [[MPMoviePlayerController alloc] init];
//set url
self.mPlayer.contentURL = btn.linked_url;
//set dimension
self.mPlayer.view.frame = self.view.frame;
//AddSubView
[self.mViewForMovie addSubview:mPlayer.view];
//Notify
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(_moviePlayerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(_moviePlayerDidFinish:) name:MPMoviePlayerDidExitFullscreenNotification object:mPlayer];
//fullscreen
[self.mPlayer setFullscreen:YES animated:YES];
//start play
[self.mPlayer play];
the problem occured when i try to click done button, this doesn't work.
Only in the area of the presentModalViewController below is possible to intercept the click.
What did I do wrong?
thanks for help
Don

Related

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

Volume Control is not showing on MPMoviePlayerController

Volume Control is not showing such that slider .
I search many answer on Stackoverflow regarding this but No code is working well.
Most of the Answers I see there is a slider which control volume and added to subview I also try this but no slider.
- (void)play
{
NSURL *url=[[NSURL alloc] initWithString:self.url];
player=[[MPMoviePlayerController alloc] initWithContentURL:url];
[player prepareToPlay];
player.allowsAirPlay = YES;
player.scalingMode = MPMovieScalingModeAspectFit;
player.view.frame = self.view.frame;
player.controlStyle = MPMovieControlStyleFullscreen;
player.useApplicationAudioSession = YES;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:player];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
if ([UIScreen mainScreen].bounds.size.height == 568)
{
[[player view] setBounds:CGRectMake(0, 0, 568, 320)];
}
else
{
[[player view] setBounds:CGRectMake(0, 0, 480, 320)];
}
// [[player view] setBounds:CGRectMake(0, 0, 480, 320)];
// [[player view] setCenter:CGPointMake(160, 240)];
[[player view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];
[self.view addSubview: player.view];
// [ self.view addSubview: systemVolumeSlider];
[player play];
}

UINavigationController setViewControllers autorotation issue

I present a UINavigationController with two view controllers in stack and present the last view controller first. And tapping the back button obviously goes back to the first view controller.
navCtrl = [[UINavigationController alloc] init];
ViewController1 *vc1 = [[ViewController1 alloc] init];
ViewController2* vc2 = [[ViewController2 alloc] init];
[navCtrl setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil] animated:NO];
[self presentViewController:navCtrl animated:YES completion:^{
}];
The problem is that when I push the back button on the navigation controller in landscape mode, view controller vc1 frame is incorrect. The frame is (0,0,320,568) and is laid out in landscape mode. I am running iOS 7. The autorotation code is not invoked on pressing the back button.
Whereas, If I present the navigation controller with the natural order vc1,vc2, I don't see any issue.
EDIT: FYI, here are the -viewWillAppear and -viewDidAppear calls in vc1 :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[[UIApplication sharedApplication] setStatusBarHidden:NO
withAnimation:UIStatusBarAnimationNone];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
NSLog(#"Frame = %#", NSStringFromCGRect(self.view.frame));
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Get status bar height if visible
if (![UIApplication sharedApplication].statusBarHidden) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGFloat statusBarHeight = MIN(statusBarFrame.size.height, statusBarFrame.size.width);
// Set navigation bar frame
CGRect navBarFrame = self.navigationController.navigationBar.frame;
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
/*
navBarFrame.origin.y = statusBarHeight;
self.navigationController.navigationBar.frame = navBarFrame;
*/
UIEdgeInsets e = UIEdgeInsetsMake(statusBarHeight + navBarFrame.size.height, 0, navBarFrame.size.height + 12, 0);
[_tableView setScrollIndicatorInsets:e];
[_tableView setContentInset:e];
}
_tableView.rowHeight = 75;
self.spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(145, 200, 30, 30);
[self.view addSubview:spinner];
[spinner startAnimating];
[self performSelector:#selector(refreshData) withObject:nil afterDelay:0.f];
}
I found the problem. For some old iOS bug workaround which I don't remember I had the following line in viewDidLoad
[self.navigationController.view setFrame: [self.navigationController.view bounds]];
There are a few things you need to check here:
You said you already checked, but lets be safe - check the Auto-Resizing on the view.
Do your view controllers implement the following method?
- (NSUInteger)supportedInterfaceOrientations;
Are you presenting the navigation controller as a child view controller? When doing that make sure the following method is returning its default YES
- (BOOL)shouldAutomaticallyForwardRotationMethods;
Check you are not adding child view controllers to the view of a UINavigationController as it doesn't forward the appearance methods, its best to handle that from within the view controllers on the navigation controller.
Failing all of the above you should put a breakpoint in viewWillAppear of vc1 and check its frame, if the frame is correct, but the navigationContoller.view frame is incorrect then you must check your auto-resizing masks.

How to play video stream with MPMoviePlayerController in iOS

I am trying to play a video stream from the internet on the iPhone by pressing a button.
I used many code samples but nothing worked. With this code it opens a black view without any video stream or controls in it. (The stream itself works.)
NSURL *url = [NSURL URLWithString:#"http://MyStreamURL.com"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
Instead of creating a MPMoviePlayerController and adding that to your view, it is probably simpler to create a MPMoviePlayerViewController and present that view controller modally (since you are trying to show your video full screen anyway). Then the MPMoviePlayerViewController can manage the presentation of your video for you.
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];
In your moviePlayBackDidFinish delegate method you can then dismiss the model view controller.
Need to mention movie source type as streaming
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Add AVFoundation frame work in Link Libraries section
In your .h file add
#import <MediaPlayer/MediaPlayer.h>
#interface video_liveViewController : UIViewController<MPMediaPickerControllerDelegate,MPMediaPlayback>
In your .m file
NSURL *movieURL = [NSURL URLWithString:#"http://172.31.17.252:1935/live/myStream/playlist.m3u8"];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:movieController];
[movieController.moviePlayer play];
just add "MPMovieSourceTypeStreaming" to "moviesourcetype"

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