0

[mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]] 出现错误;它说 initWithContentURL 是一个未声明的标识符。我该如何解决?

导入“ViewController.h”

@interface ViewController ()
{
    MPMoviePlayerController *mpc;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)playButton:(id)sender {
    NSString *stringpath;[[NSBundle mainBundle]pathForResource:@"Lake Weekend September 13-14" ofType:@"m4v"];
    NSURL *url = [[[NSURL fileURLWithPath:stringpath]
    [mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];
    [mpc setMovieSourceType:MPMovieSourceTypeFile];
    
    [[self view ]addSubview:mpc.view];
    
    [mpc setFullscreen:YES];
    
    [mpc play];
}
@end
4

2 回答 2

0

你的 mpc 的 alloc/init 看起来都错了。那条线在我看来都是乱码。我认为那行应该是这样的:

mpc=[[MPMoviePlayerController alloc] initWithContentURL: url];
于 2013-10-05T18:53:52.350 回答
0

您在使用之前没有声明 url 吗?你试图在它的声明中使用它......

NSURL *url = [[[NSURL fileURLWithPath:stringpath]
[mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];

您至少应该在第一行之后有一个分号..然后您将能够使用 url。另外,您需要整理额外的括号,试试这个..

NSURL *url = [NSURL fileURLWithPath:stringpath];
mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];
于 2013-10-05T18:48:46.263 回答