Link to home
Start Free TrialLog in
Avatar of redribbon14
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:videoURL];
videoplayer.view.frame =CGRectMake(20,7, 804, 473);
videoplayer.scalingMode = MPMovieScalingModeFill;
[secondscroll addSubview:videoplayer.view];
videoplayer.controlStyle = MPMovieControlStyleNone;
[videoplayer.backgroundView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test2.png"]]];
videoplayer.view.backgroundColor = [UIColor clearColor];
[videoplayer play];
videoplayer.repeatMode = MPMovieRepeatModeOne;

}

-(IBAction)showview:(id)sender {
[secondscroll scrollRectToVisible:CGRectMake(0, 0, 846,538) animated:NO];


secondscroll.clipsToBounds = NO;
secondscroll.pagingEnabled = YES;
secondscroll.showsVerticalScrollIndicator = NO;
[secondscroll setContentSize:CGSizeMake(846, 1830)];



[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelay:0.1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];


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 setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

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.
ASKER CERTIFIED SOLUTION
Avatar of redribbon14
redribbon14

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of redribbon14
redribbon14

ASKER

regretting on joining this site, again.