0

我想創建一個應用程序與我的視頻在UIButton視圖中播放。僅供參考:我正在使用帶有標籤欄視圖控制器的故事板,因此此代碼MPMoviePlayerView位於另一個視圖內。MPMoviePlayer無法在應用程序中工作

我不斷收到此錯誤:*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: '* - [NSURL initFileURLWithPath:]:零字符串參數'

這裏是我的代碼:

VideoTefViewController.h

#import <UIKit/UIKit.h> 

@interface VideoTefViewController : UIViewController 


-(IBAction)playMovie; 
@end 

VideoTefViewController.m

#import "VideoTefViewController.h" 
#import <MediaPlayer/MediaPlayer.h> 
@interface VideoTefViewController() 

@end 

@implementation VideoTefViewController 

-(IBAction)playMovie { 

    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *moviePath = [bundle pathForResource:@"tef" ofType:@"mp4"]; 
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath]; 
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
    theMovie.scalingMode = MPMovieScalingModeAspectFill; 
    [theMovie play]; 
} 

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

} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

回答

0

錯誤是告訴你fileURLWithPath的參數是零,所以出於某種原因,moviePath是零。你確定你的包中有一個名爲tef.mp4的文件嗎?

+0

我確定我的項目中有一個名爲tef.mp4的文件。它位於xcode的支持文件/資源​​文件文件夾中。我應該放在別的地方嗎? – jakife 2012-07-24 11:40:45

+0

@YuvalMarcus,請嘗試在創建它的行後面記錄moviePath,看看它是否爲零。 – rdelmar 2012-07-24 15:15:03

+0

所以我應該寫:NSlog是什麼? – jakife 2012-07-24 23:04:10

相關問題