how to remove animation from the MPMoviePlayerController when done is pressed - ios

I want to remove the transition animation that occur in MPMoviePLayerController when the user presses done button . I used to stop it when the movie finishes on its own using the moviePlayBackDidFinish: notification but its doesn't work, as in, the animation occurs. this code i used.
NSURL *fileURL=[NSURL URLWithString:mediaurl1];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 150, 320, 270)];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(donefinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[mediaView addSubview:moviePlayerController.view];
[moviePlayerController setFullscreen:YES animated:NO];
moviePlayerController.useApplicationAudioSession = YES;
[moviePlayerController play];
this is my notification method to close the animation effect.
-(void)doneButtonClick:(NSNotification*)aNotification{
[mediaView removeFromSuperview ];
[moviePlayerController setFullscreen:NO animated:NO];
[self dismissViewControllerAnimated:NO completion:NO];
// [moviePlayerController setFullscreen:NO animated:NO];
}
-(void)donefinished:(NSNotification*)aNotification{
[mediaView removeFromSuperview ];
[moviePlayerController setFullscreen:NO animated:NO];
[self dismissViewControllerAnimated:NO completion:NO];
// [moviePlayerController setFullscreen:NO animated:NO];
}

Use it.
-(void)donefinished:(NSNotification*)aNotification
{
[moviePlayerController stop];
[moviePlayerController.view removeFromSuperview];
moviePlayerController = nil;
}

Related

AVPlayerviewcontroller is not dismissing

I am doing one application. In that I used the AVPlayerViewController to play the video. But its not dismiss after play the video.
Please check the my source:
_player = [AVPlayer playerWithURL:self.videoURL];
_avVideoController = [[AVPlayerViewController alloc]init];
_avVideoController.view.frame = self.view.frame;
_avVideoController.delegate =self;
_avVideoController.player.actionAtItemEnd = AVPlayerActionAtItemEndAdvance;
_avVideoController.player = _player;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[_avVideoController.player currentItem]];
[_player play];
[self.view addSubview:_avVideoController.view];
[self presentViewController:_avVideoController animated:YES completion:nil];
- (void)playerItemDidReachEnd:(NSNotification *)notification
{
[_avVideoController dismissViewControllerAnimated:YES completion:nil];
[_avVideoController.view removeFromSuperview];
NSLog(#"IT REACHED THE END");
}
After this AVPlayerViewController is not dismissing.
Not hundred percent sure, but might be because of NSNotificationCenter still keeps a reference to self. Try to remove observer in
- (void)playerItemDidReachEnd:(NSNotification *)notification function. As of that
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:nil];

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

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

MPMoviePlayerControler fullscreen problem if opened on PresentModalViewController in 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

MPMoviePlayerViewController Hide Status Bar

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 :)

Resources