"MPMoviePlayerController"已被弃用:自iOS 9.0起首次被弃用。

3

已经有人用Swift回答了这个问题:
MPMoviePlayerController'在swift中已经被弃用,我想要Objective-C的解决方法。

我收到了这个警告:

'MPMoviePlayerController'已被弃用:从iOS 9.0开始被弃用

这是我的代码:

MPMoviePlayerController* _moviePlayer;
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:contentURL];
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];

1
你看过文档 https://developer.apple.com/reference/mediaplayer/mpmovieplayercontroller 吗?它告诉你可以用什么类型的对象来替换它。 - Larme
1
我点了踩,因为答案已经在文档中并且很容易找到。如果你展示了使用AVPlayerViewController或者AVPictureInPictureController的代码,我就不会这么做了。另外,在链接的问题中,有5/6行代码,这些代码并不是很复杂,因为方法名几乎与Objective-C中的方法名相同。 - Larme
不行,你不能说是重复的,因为它是用 Swift 语言编写的,并且我在标签中提到了 Objective-C。我不知道 Swift,现在该如何实现??? - Mihir Oza
1
请问您是想了解关于AVPlayerViewController无法加载远程URL的问题吗? - Larme
2
语言在这里完全无关紧要。这是一个关于框架的问题。 - jscs
1个回答

10

在@Larme的帮助下,我解决了我的问题。
1)我添加了两个框架。

#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>  

2) 我用以下代码替换了原先的代码

AVPlayerViewController * _moviePlayer1 = [[AVPlayerViewController alloc] init];
    _moviePlayer1.player = [AVPlayer playerWithURL:_img.contentURL];

    [self presentViewController:_moviePlayer1 animated:YES completion:^{
        [_moviePlayer1.player play];
    }];  

我希望它能帮助任何遇到这个问题的人。


能否播放YouTube视频? - Raviteja Mathangi
对于 YouTube 视频,您需要使用 webView。这是链接,请查看 https://developers.google.com/youtube/v3/guides/ios_youtube_helper - Mihir Oza

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接