2012-08-24 206 views
0

在用Objective-C查看了如何播放電影之後,它似乎很直接。我使用的代碼如下:無法播放視頻

- (void) createMovie { 
    NSLog(@"create movie method called"); 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"walkthrough" ofType:@"mp4"]; 

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; 
    player.view.frame = CGRectMake(184, 200, 400, 300); 
    [self.view addSubview:player.view]; 
    [player play]; 

} 

我在我的頭文件中包含了合適的#import <MediaPlayer/MediaPlayer.h>。當視圖加載我可以看到一個黑盒子,我認爲是播放器視圖的框架,但沒有視頻。誰能幫忙?

回答

1

嘗試移出您的功能MPMoviePlayerController *moviePlayer。 (就像.h文件或者在函數上面一樣)。然後執行:

player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; 

我想你一旦離開函數就會釋放它。

+0

沒關係,只是注意到它自己,謝謝 – garethdn