I am using MPMoviePlayerController but I am getting the issue is that its repeats only two times but I have to repeat it continuously how to do that please any one suggest me better way for it.
-(void)viewDidLoad
{
player = [[MPMoviePlayerController alloc] initWithContentURL:outPutUrl];
player.view.frame = CGRectMake(0, 0, 320, 480);
player.repeatMode = MPMovieRepeatModeOne;
[player setShouldAutoplay:YES];
[player prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player setControlStyle:MPMovieControlStyleNone];
[self.imgView addSubview:player.view];
[player play];
}
-(void)moviePlayerDidFinish:(NSNotification *)note
{
if (note.object == player)
{
NSLog(#"this is note%#",note.object);
NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[player play];
}
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"drvo_hd_final-1" ofType:#"mp4"]]];
player.view.frame = CGRectMake(20, 20, 280, 200);
player.repeatMode = MPMovieRepeatModeOne;
[player setShouldAutoplay:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player setControlStyle:MPMovieControlModeDefault];
[self.view addSubview:player.view];
[player prepareToPlay];
}
- (void)moviePlayerDidFinish:(NSNotification *)note
{
if (note.object == player)
{
NSLog(#"this is note%#",note.object);
NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[player prepareToPlay];
}
}
}
This is working for me and playing continuously.....
Related
I am using the MPMoviePlayerController to open a video file.The video runs fine.But suppose if the video file is 10 sec ,with 1 sec remaining the video stops.Is that its natural way of playing or should we specify something.The follow is the code used
NSURL *fileURL = [NSURL URLWithString:location];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
self.moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController.view setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:self.moviePlayerController.view];
- (void)moviePlaybackComplete:(NSNotification *)notification {
NSNumber *finishReason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded) {
self.moviePlayerController = [notification object];
self.moviePlayerController.view.hidden = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController.view removeFromSuperview];
[self.moviePlayerController release];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
The background image is an animated sky
When switching between settings page (static image) and the home page (animated image) the screen animation often drops off and becomes a single black image
Can anybody suggest a reason or a solution?
Thanks!
Henry Colour Vision Apps
- (void)viewDidLoad
{
[super viewDidLoad];
self.mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"iPhone4" ofType:#"mov"]]];
mp.repeatMode = MPMovieRepeatModeOne;
[mp.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
mp.scalingMode = MPMovieScalingModeFill;
[mp setFullscreen:YES];
mp.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:mp.view];
[self.view sendSubviewToBack:mp.view];
[mp prepareToPlay];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mp play];
}
Try add a observer to your player. Like this:
- (void)viewDidLoad
{
///...
self.mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"iPhone4" ofType:#"mov"]]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mp];
///...
}
Then you can get what's wrong:
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(#"Movie Finished.");
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackError) {
NSDictionary *notificationUserInfo = [notification userInfo];
NSError *mediaPlayerError = [notificationUserInfo objectForKey:#"error"];
if (mediaPlayerError)
{
NSLog(#"playback failed with error description: %#", [mediaPlayerError localizedDescription]);
}
else
{
NSLog(#"playback failed without any given reason");
}
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.mp];
}
I have used a MPMoviePlayerController object to play a movie in my app but as soon as I call [moviePlayer play] in a function there is a small jerk and then the movie starts playing.
Edit:
This is the code that I am using.
NSString *urlStr = [[NSBundle mainBundle] pathForResource:sVideoName ofType:nil];
NSURL *movieURL = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.view.frame = CGRectMake(lowerScroll.frame.size.width *(((AppDelegate *)[UIApplication sharedApplication].delegate).currentPage-1), 0.0,1024.0,lowerScroll.frame.size.height);
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeFill;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.view.backgroundColor = [UIColor clearColor];
moviePlayer.view.alpha = 0;
[lowerScroll addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[self performSelector:#selector(showMovie) withObject:nil afterDelay:0.3];
- (void)showMovie {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[moviePlayer play];
moviePlayer.view.alpha = 1;
[UIView commitAnimations];
}
- (void)movieFinishedCallback:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if (moviePlayer) {
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
moviePlayer = nil;
}
}
Could anybody please tell what could be the reason for the same and how to remove that jerk.
Thanx in advance.
I am playing a video by using MPMoviePlayerController:
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"myvideo.MOV" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0,0, 1024, 675);
[moviePlayer play];
But requirement is that by default video should be in full screen and when I minimize it should be in above frame size.
Please help me out.
Try this.
#define degreesToRadian(x) (M_PI * (x) / 180.0)
-(void)playMovieAtURL:(NSURL*)movieURL
{
if ([NSClassFromString(#"MPMoviePlayerController") instancesRespondToSelector:#selector(view)])
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
// running iOS 3.2 or better
mViewPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
mViewPlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
CGRect newFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
mViewPlayer.view.frame = newFrame;
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[mViewPlayer.view setTransform: landscapeTransform];
[self.view addSubview:mViewPlayer.view];
[mViewPlayer.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieDidExitFullscreen:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[mViewPlayer moviePlayer]];
#endif
}
else
{
MPMoviePlayerController *mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
mMPPlayer.scalingMode=MPMovieScalingModeFill;
mMPPlayer.backgroundColor=[UIColor blackColor];
[mMPPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMPPlayer];
}
}
/*---------------------------------------------------------------------------
*
*--------------------------------------------------------------------------*/
- (void) movieDidExitFullscreen:(NSNotification*)notification
{
//[[UIApplication sharedApplication] setStatusBarHidden:YES];
/*/ Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];*/
[[NSNotificationCenter defaultCenter] removeObserver: self
name:MPMoviePlayerPlaybackDidFinishNotification
object: [notification object]];
MPMoviePlayerController *theMovie1 = [notification object];
[theMovie1.view removeFromSuperview];
[theMovie1 release];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
//[[UIApplication sharedApplication] setStatusBarHidden:YES];
/*/ Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];*/
[[NSNotificationCenter defaultCenter] removeObserver: self
name:MPMoviePlayerPlaybackDidFinishNotification
object: [notification object]];
MPMoviePlayerController *theMovie1 = [notification object];
[theMovie1.view removeFromSuperview];
[theMovie1 release];
}
I am running an intro movie in a MPMoviePlayerController and i've got a problem with the allocated memory not being released.
When the movie finishes, Instruments shows the memory being released.
However when i skip the movie by tapping on it the memory is not released.
Here are the important parts of my code:
- (void)applicationDidFinishLaunching:(UIApplication *)theApplication {
self.application = theApplication;
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"mymovie.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[window addSubview:moviePlayer.view];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = window.frame;
UIView *introFrontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
introFrontView.userInteractionEnabled = YES;
introFrontView.opaque = NO;
introTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(introTabFrom:)];
[introFrontView addGestureRecognizer:introTabRecognizer];
[moviePlayer.view addSubview:introFrontView];
[introFrontView release];
[introTabRecognizer release];
self.moviePlayerController = moviePlayer;
[moviePlayer release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(introFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController play];
}
- (void)introTabFrom:(UITapGestureRecognizer*)recognizer{
[[NSNotificationCenter defaultCenter] postNotificationName:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
}
- (void) introFinished:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController pause];
[self.moviePlayerController stop];
[self.moviePlayerController release];
...
}
Is there anything i forgot? To my understanding i'm posting the correct notification...
Any ideas?
You may want to register for MPMoviePlayerPlaybackStateDidChangeNotification, and look at the playbackState that is passed in.