ios 进阶 -- 开机视频



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ‘’‘’‘’
    
    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
    NSURL *fileURL = [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    [self.viewController.view addSubview:theMovie.view];
    theMovie.fullscreen = YES;
    theMovie.controlStyle = MPMovieControlStyleNone;
    
    if ([theMovie respondsToSelector:@selector(prepareToPlay)]) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(stopPlayerCallback:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:theMovie];
        
        [theMovie prepareToPlay];
    }
    return YES;
}

播放完视频后,


-(void)stopPlayerCallback:(NSNotification*)aNotification
{
    MPMoviePlayerController* theMovie = [aNotification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
                                                      object:theMovie];
    
    [theMovie.view removeFromSuperview];

 
}

源码下载

版权所有:http://blog.csdn.net/sea918

你可能感兴趣的:(【ios,应用程序】)