0

我正在尝试使用我的视频创建一个应用程序,以便在带有 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
4

1 回答 1

0

该错误告诉您 fileURLWithPath: 的参数为 nil,因此由于某种原因 moviePath 为 nil。你确定你的包中有一个名为 tef.mp4 的文件吗?

于 2012-07-24T03:12:50.003 回答