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

Posted on 2012-08-16
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

    Accepted Solution

    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

    regretting on joining this site, again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    There are many out there who own an iPad but are frustrated by the lack of Flash support. This prevents many webpages from displaying their content correctly on the iPad .  In addition Flash games are not supported on the iPad either.  Regardless of…
    What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now