我正在尝试使用我的视频创建一个应用程序,以便在带有 UIButton 的视图中播放。仅供参考:我正在使用带有标签栏视图控制器的情节提要,因此此代码 MPMoviePlayerView 位于另一个视图中。
我不断收到此错误:* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSURL initFileURLWithPath:]: nil string parameter”
这是我的代码:
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