Search code examples
iosobjective-cios9mpmovieplayercontrollerdeprecated

'MPMoviePlayerController' is deprecated: first deprecated in iOS 9.0


Already someone answer this question in swift
MPMoviePlayerController' is deprecated in swift I want this in Objective-C.

I am getting this warning

'MPMoviePlayerController' is deprecated: first deprecated in iOS 9.0

Here is my code :

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

Solution

  • With the help of @Larme I resolved my Issue.
    1) I added two frameworks

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

    2) I replace my code with

    AVPlayerViewController * _moviePlayer1 = [[AVPlayerViewController alloc] init];
        _moviePlayer1.player = [AVPlayer playerWithURL:_img.contentURL];
    
        [self presentViewController:_moviePlayer1 animated:YES completion:^{
            [_moviePlayer1.player play];
        }];  
    

    I hope it will help who ever face this issue .