【问题标题】:MPMoviePlayerController - xcode not finding it and screenMPMoviePlayerController - xcode 找不到它和屏幕
【发布时间】:2013-11-05 02:15:52
【问题描述】:

我正在尝试使用 MPMoviePlayerController 播放捆绑包中的视频,并显示“使用未声明的标识符 'MPMoviePlayerController'”。我是否需要导入任何库才能使用此类?另外,我想知道如何不全屏播放,以及如何选择播放框的大小。

代码:

NSString *url = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
moviePlayer.shouldAutoplay=YES;
CGRect videoRect = CGRectMake(0, 0, 300, 250); 
moviePlayer.view.frame = videoRect;
[self.view  addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

【问题讨论】:

    标签: ios objective-c mpmovieplayercontroller


    【解决方案1】:

    您需要导入/包含电影播放器​​:MediaPlayer/MediaPlayer.h

    此外,必须将 MediaPlayer.framework 添加到 XCode 项目中的“Frameworks”文件夹中。

    不全屏播放:

    self.moviePlayer.shouldAutoplay=YES;
    CGRect videoRect = CGRectMake(0, 0, 300, 250); // define the player's dimensions in compact mode here its 300 * 250
    self.moviePlayer.view.frame = videoRect;
    [self.view  addSubview:self.moviePlayer.view];
    

    【讨论】:

    • 对不起,我是初学者,如何添加框架?谢谢。
    • 在导航器中点击项目,进入构建阶段,在链接二进制与库部分点击添加图标并搜索您想要的库。您也可以手动添加它,右键单击项目中的框架 -> 添加文件并导航到该位置(位于 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7. 0.sdk/System/Library/Frameworks 为我)
    • 现在它做了一个盒子,但它是空的!视频无法播放。我编辑了代码
    • 哦,moviePlayer 必须是一个属性。现在好了。再次感谢
    猜你喜欢
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多