redribbon14
asked on
how to stop and play video(mpmovieplayer) inside uiscrollview in xcode
hello all,
so, I'm starting my interactive cooking tutorial app 3months ago and its about 90% done here(the menu, user GUI,etc). the only problem is i don't have any idea how to make a video stop and playing automatically just by swiping inside the uiscrollview(vertically with paging enabled on, and were arrange in xib not programmatically).
so i have one uiscrollview with like 5 video inside, when the uiview start to launch, the first video will start automatically. now when user scroll to the second video, i want that first video to stop and play the second video automatically and so on. here's what I already did :
-(void)videodelay {
NSString *urlstr = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:urlstr];
videoplayer = [[MPMoviePlayerController alloc] initWithContentURL:videoUR L];
videoplayer.view.frame =CGRectMake(20,7, 804, 473);
videoplayer.scalingMode = MPMovieScalingModeFill;
[secondscroll addSubview:videoplayer.vie w];
videoplayer.controlStyle = MPMovieControlStyleNone;
[videoplayer.backgroundVie w addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test2.png"]]] ;
videoplayer.view.backgroun dColor = [UIColor clearColor];
[videoplayer play];
videoplayer.repeatMode = MPMovieRepeatModeOne;
}
-(IBAction)showview:(id)se nder {
[secondscroll scrollRectToVisible:CGRect Make(0, 0, 846,538) animated:NO];
secondscroll.clipsToBounds = NO;
secondscroll.pagingEnabled = YES;
secondscroll.showsVertical ScrollIndi cator = NO;
[secondscroll setContentSize:CGSizeMake( 846, 1830)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurr entState:Y ES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelay:0.1];
[UIView setAnimationCurve:UIViewAn imationCur veEaseOut] ;
mainview.frame = CGRectMake(-1024, 0, 1024, 768);
secondview.frame = CGRectMake(0, 0, 1024, 768);
hidebtn.hidden = YES;
img.frame = CGRectMake(287, 748, 450, 300);
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurr entState:Y ES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAn imationCur veEaseOut] ;
showsidebtn.frame = CGRectMake(495, 704, 93, 37);
side.frame = CGRectMake(994, 0, 150, 768);
left.frame = CGRectMake(-120, 0, 150, 768);
[UIView commitAnimations];
[self performSelector:@selector( videodelay ) withObject:nil afterDelay:1.5];
}
I've been playing around with only 3video files and ill implemented the code to my apps if i found the way to do it.
i really hope someone here can help me by giving a clue or an idea how to get it work. . thank you guys, and I'm sorry for my english since its not my native tounge.
so, I'm starting my interactive cooking tutorial app 3months ago and its about 90% done here(the menu, user GUI,etc). the only problem is i don't have any idea how to make a video stop and playing automatically just by swiping inside the uiscrollview(vertically with paging enabled on, and were arrange in xib not programmatically).
so i have one uiscrollview with like 5 video inside, when the uiview start to launch, the first video will start automatically. now when user scroll to the second video, i want that first video to stop and play the second video automatically and so on. here's what I already did :
-(void)videodelay {
NSString *urlstr = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"mov"];
videoURL = [NSURL fileURLWithPath:urlstr];
videoplayer = [[MPMoviePlayerController alloc] initWithContentURL:videoUR
videoplayer.view.frame =CGRectMake(20,7, 804, 473);
videoplayer.scalingMode = MPMovieScalingModeFill;
[secondscroll addSubview:videoplayer.vie
videoplayer.controlStyle = MPMovieControlStyleNone;
[videoplayer.backgroundVie
videoplayer.view.backgroun
[videoplayer play];
videoplayer.repeatMode = MPMovieRepeatModeOne;
}
-(IBAction)showview:(id)se
[secondscroll scrollRectToVisible:CGRect
secondscroll.clipsToBounds
secondscroll.pagingEnabled
secondscroll.showsVertical
[secondscroll setContentSize:CGSizeMake(
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurr
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelay:0.1];
[UIView setAnimationCurve:UIViewAn
mainview.frame = CGRectMake(-1024, 0, 1024, 768);
secondview.frame = CGRectMake(0, 0, 1024, 768);
hidebtn.hidden = YES;
img.frame = CGRectMake(287, 748, 450, 300);
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurr
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAn
showsidebtn.frame = CGRectMake(495, 704, 93, 37);
side.frame = CGRectMake(994, 0, 150, 768);
left.frame = CGRectMake(-120, 0, 150, 768);
[UIView commitAnimations];
[self performSelector:@selector(
}
I've been playing around with only 3video files and ill implemented the code to my apps if i found the way to do it.
i really hope someone here can help me by giving a clue or an idea how to get it work. . thank you guys, and I'm sorry for my english since its not my native tounge.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER