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
我確定我的項目中有一個名爲tef.mp4的文件。它位於xcode的支持文件/資源文件文件夾中。我應該放在別的地方嗎? – jakife 2012-07-24 11:40:45
@YuvalMarcus,請嘗試在創建它的行後面記錄moviePath,看看它是否爲零。 – rdelmar 2012-07-24 15:15:03
所以我應該寫:NSlog是什麼? – jakife 2012-07-24 23:04:10