2012-05-11 61 views
0

`我面臨問題,以開發在ios5 Xcode編程中運行mp4視頻的代碼。 當我運行的應用程序關注的是,雖然顯示文件clip2.mp4在我bundle.please給我一個 妥善解決視頻播放器不工作在Xcode 4.2

- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

    NSString *url = [[NSBundle mainBundle] 
       pathForResource:@"clip2" 
       ofType:@"mp4"]; 
player =[[MPMoviePlayerController alloc] 
    initWithContentURL:[NSURL fileURLWithPath:url]]; 
    [player prepareToPlay]; 
    [player play];  


    [[NSNotificationCenter defaultCenter] 
addObserver:self 
    selector:@selector(movieFinishedCallback:)             
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player]; 

    //---play movie--- 

} 

    - (void) movieFinishedCallback:(NSNotification*) aNotification { 
    MPMoviePlayerController *play= [aNotification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:play];  
//[player autorelease];  
    } ` 

回答

0

應該

player = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

url已經是一個NSURL-fileURLWithPath:用於從包含文件路徑(即/path/to/file)而不是正常URL(即http://stackoverflow.com/

NSString創建 NSURL