Stuck with video problems

Discussion in 'iOS Programming' started by Appline, May 1, 2012.

  1. Appline macrumors newbie

    Joined:
    Apr 17, 2012
    #1
    Hey there everyone, I'm trying to put a splashvideo instead of a boring splashscreen in my project, I've been looking on the entire web without find anything but I feel close to solution.
    Code:
    @implementation SplashVideo_1AppDelegate
    
    @synthesize window=_window;
    
    
    MPMoviePlayerController *player;
    
    
    - (void)dealloc
    {
        [_window release];
        [super dealloc];
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       
        // Override point for customization after application launch.
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Splashvideo" ofType:@"m4v"];
                                  
        MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
        player.fullscreen=YES;
        [player prepareToPlay];
        player.controlStyle=MPMovieControlStyleNone;
       [[player view] setFrame:_window.bounds];
         [self.window addSubview:[player view]]; 
            [player play];
        
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
        
    
       
               
        
        return YES;
    
    }
    
    -(void) moviePlayBackDidFinish {
    
        [player.view removeFromSuperview];
        [player release ];
        [_window makeKeyAndVisible];
        
        
    }
    with this code in the app delegate i can hear the sound of my video but i can't see it even if i said to the program to show me the window when the movie is over.

    could anyone help me?

    P.S. sorry for my bad english
     
  2. Appline thread starter macrumors newbie

    Joined:
    Apr 17, 2012
    #2
    ok now i'm closer!!
    Code:
    @implementation SplashVideo_1AppDelegate
    
    @synthesize window=_window;
    
    
    MPMoviePlayerController *player;
    
    
    - (void)dealloc
    {
        [_window release];
        [super dealloc];
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       
        // Override point for customization after application launch.
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Splashvideo" ofType:@"m4v"];
                                  
        MPMoviePlayerViewController *player =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
       /* player.fullscreen=YES;
        [player prepareToPlay];
        player.controlStyle=MPMovieControlStyleNone;*/
       [[player view] setFrame:_window.bounds];
         [self.window addSubview:[player view]]; 
        self.window.rootViewController.view=player.moviePlayer.view;
        
            player.moviePlayer.shouldAutoplay=YES;
        
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
        
    
       
               
        
        return YES;
    
    }
    
    -(void) moviePlayBackDidFinish {
    
        [player.view removeFromSuperview];
        [player release ];
        [_window makeKeyAndVisible];
        
        
    }
    
    Now the first thing that see it's the video the only thing is that i'm stuck in the video and i can't get out this must be some moviePlayBackDidFinish problem but MPMoviePlayerViewController can't handle the playback finish statement :(
     
  3. nickculbertson macrumors regular

    nickculbertson

    Joined:
    Nov 19, 2010
    Location:
    Nashville, TN
    #3
    I'm not a fan of heavy lifting in the app delegate. I'd rather create an IBAction in the main viewcontroller that is called from the app delegate.

    Code:
    //app delegate
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        
        [viewController startmovie];
    
        [self.window addSubview:viewController.view];
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    
    //myviewcontroller.m
    
    -(IBAction)startmovie{
    //play movie
    }
    
    
    Nick
     

Share This Page