2013-02-21 125 views
1

我試圖從項目目錄加載視頻,任何人可以建議,我到底錯過了什麼。視頻播放器不加載文件

NSURL *myURL =[[NSBundle mainBundle] URLForResource:@"US_Very_High_Dive_Boudia_US_44_x264" 
withExtension:@"mp4"]; 

MPMoviePlayerController *player = 
[[MPMoviePlayerController alloc] initWithContentURL: myURL]; 

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


[player prepareToPlay]; 
[player shouldAutoplay]; 
[player allowsAirPlay]; 
[self.view addSubview:player.view]; 
[player setFullscreen:YES animated:YES]; 

player.controlStyle=MPMovieControlStyleEmbedded; 

回答

2

試試這個代碼

在.h文件中添加以下

@property (nonatomic, strong) MPMoviePlayerController *controller; 

在.m文件

-(IBAction)playMovie:(id)sender 

      { 
       NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"]; 
       NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
       MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
       [self.view addSubview:moviePlayerController.view]; 
       moviePlayerController.fullscreen = YES; 
      [moviePlayerController prepareToPlay]; 
       [moviePlayerController play]; 
     [self setController:moviePlayerController]; 
      } 
+0

非常棒的人完美地工作,謝謝。 – Alex 2013-02-21 08:35:59

0

好像你沒有正確設置URL - 試試這個:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
pathForResource:@"filename" ofType:@"mp4"]]; 
+0

不工作,它只是加載 – Alex 2013-02-21 08:32:55