Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to stop and play video(mpmovieplayer) inside uiscrollview in xcode

Posted on 2012-08-16
Medium Priority
Last Modified: 2013-11-17
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.
Question by:redribbon14
  • 2

Accepted Solution

redribbon14 earned 0 total points
ID: 38359899
its so sad when you cant find any sites that can help you with the question especially a PAID one. not even a clue or idea how this trick can be done. bad decission when im joining this site again for the second time since 2009. i can only find a simple question with an answer in this site that you can find for free on any other site. thanks anyway, im out.

Author Closing Comment

ID: 38359901
regretting on joining this site, again.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The release of the iPhone 6 and the iPhone 6 Plus was extremely successful for Apple. However when iOS 8.1 was introduced, many iPhone users complained of quick battery drainage. Without even knowing, you may be unnecessarily using up your battery …
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question