2011-03-24 142 views
0

我已经写下这段用于在触摸图像后播放视频的Objective-C代码。iPhone框架视频播放

//start video here 
    NSString *path = [self localVideoPath:NO]; 

    // Create custom movie player 
    MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease]; 

    [moviePlayer setControlStyle:MPMovieControlStyleNone]; 

    [[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(onMSAASDone:) 
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:moviePlayer]; 

    [moviePlayer setScalingMode:MPMovieScalingModeAspectFill]; 
    [moviePlayer setFullscreen:FALSE]; 

    //---play partial screen--- 
    moviePlayer.view.frame = CGRectMake(0, 0, 200, 300); 
    //[[moviePlayer view] setFrame: [image bounds]]; 

    [self.view addSubview:moviePlayer.view]; 

    // Show the movie player as modal 
    //[self presentModalViewController:moviePlayer animated:YES]; 

    // Prep and play the movie 
    [moviePlayer play]; 

问题是代码在语句的第二行停止工作。错误是...程序GDB:收到信号:“EXC_BAD_ACCESS”

请帮我!

回答

0
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease]; 

功能initWithPathMPMoviePlayerController类, 我找不到它在文档中的一部分。 可能是你试图使用

- (id)initWithContentURL:(NSURL *)url 

PLZ阅读苹果文档。

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

+0

Thnaks这将真正帮助 – Neutralizer 2011-03-25 07:25:06

+0

@Umair阿什拉夫:我很高兴知道它帮助ü... – Jhaliya 2011-03-25 07:28:14

+0

@Umair阿什拉夫:接受我的答案... – Jhaliya 2011-03-25 07:38:45