[Assistance Required] Separate Movies on Separate Buttons

Discussion in 'iOS Development' started by cocotutch, Jun 18, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Hey all,

    bamhm182 and myself are working on an AppStore project, and we have run into a little roadblock.

    We have a UI with two buttons. On the first button we want Video1 to play, that works. But on Button 2 we want Video2 to play, and it works the first time, but after clicking Done or watching the videos, both buttons still function the way we want, except the video of the videos doesn't launch, it only plays the separate audio tracks.

    Here is out code:

    Code:
    #import "MainView.h"
    
    @implementation MainView
    
    
    -(void)awakeFromNib {
    	
    }
    
    
    - (IBAction)play:(id)sender {
    	
    	
    	
    	NSBundle *bundle = [NSBundle mainBundle]; //Use only if local video 
    	NSString *moviePath = [bundle pathForResource:@"video" ofType:@"m4v"];
    	
    	
    	NSURL *movieURL;
    	
    	
    	if (moviePath)
    	{
    		movieURL = [NSURL fileURLWithPath:moviePath];
    	}
    	
    	
    	if (movieURL != nil) {
    		moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    		
    		// Register to receive a notification when the movie has finished playing. 
    		[[NSNotificationCenter defaultCenter] addObserver:self
    												 selector:@selector(moviePlayBackDidFinish:) 
    													 name:MPMoviePlayerPlaybackDidFinishNotification 
    												   object:moviePlayer];
    		
    		moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    		moviePlayer.movieControlMode = MPMovieControlModeDefault;
    		moviePlayer.backgroundColor = [UIColor blackColor];
    		
    		//Starts the video as soon as the application starts
    		
    	}
        [moviePlayer play];
    }
    
    - (IBAction)play2:(id)sender {
    	NSBundle *bundle2 = [NSBundle mainBundle]; //Use only if local video 
    	NSString *moviePath2 = [bundle2 pathForResource:@"video-8" ofType:@"m4v"];
    	NSURL *movieURL2;
    	if (moviePath2)
    	{
    		movieURL2 = [NSURL fileURLWithPath:moviePath2];
    	}
    	if (movieURL2 != nil) {
    		moviePlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:movieURL2];
    		
    		// Register to receive a notification when the movie has finished playing. 
    		[[NSNotificationCenter defaultCenter] addObserver:self
    												 selector:@selector(moviePlayBackDidFinish2:) 
    													 name:MPMoviePlayerPlaybackDidFinishNotification 
    												   object:moviePlayer2];
    		
    		moviePlayer2.scalingMode = MPMovieScalingModeAspectFit; 
    		moviePlayer2.movieControlMode = MPMovieControlModeDefault;
    		moviePlayer2.backgroundColor = [UIColor blackColor];
    		
    		//Starts the video as soon as the application starts
    		
    	}
        [moviePlayer2 play];
    }
    
    -(void)moviePlayBackDidFinish: (NSNotification*)notification
    {
    	moviePlayer = [notification object];
    	
    	[moviePlayer stop];
    	
    	
    }
    
    -(void)moviePlayBackDidFinish2: (NSNotification*)notification
    {
    	
    	moviePlayer2 = [notification object];
    	
    	[moviePlayer2 stop];
    	
    }
    @end
    Please help us,

    Thankyou on behalf of myself and bamhm182,

    CT
    ------------------double post merged------------------
    Please close this, we were being tired idiots. We nutted this out alright

    Please Register or Log in to view images



    CT

Share This Page