2

我使用的是cocos2d,我想播放電影。MPMoviePlayerController不想工作

我創建了一個CCLayer子類,並重新實現它init方法是這樣的:

-(id) init 
{ 
    self = [super init]; 
    if (self) 
    { 
     NSURL *url = [NSURL fileURLWithPath:@"common/test-movie.mp4"]; 
     MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
     [[[CCDirector sharedDirector] openGLView] addSubview:[player view]]; 
     [player play]; 
    } 
    return self; 
} 

我已經運行[[CCDirector sharedDirector] runWithScene:scene];與場景只包含這一層。但沒有什麼是顯示:(只是一個黑色的屏幕

編輯

而且它總是返回0持續時間,每部電影我甚至試圖播放從iPhone的攝像頭的視頻 - 。同樣的結果

回答

3

的問題是在NSURL - 我是在不正確的方式創建它下面是正確的代碼:

NSString *rootPath = [[NSBundle mainBundle] resourcePath]; 
NSString *filePath = [rootPath stringByAppendingPathComponent:@"test-movie.mp4"]; 
NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO]; 
1

你有沒有嘗試設置視圖框

id parentView = [[CCDirector sharedDirector] openGLView]; 
[parentView addSubview:[player view]]; 
[[player view] setFrame:[parentView bounds]]; 
+0

沒有幫助。玩家的控制也沒有顯示 – Andrew 2011-01-26 17:39:10