2

I'm making an iOS app with objective-c.
Please tell me how to fix AVPlayerView in iOS13.x environment.

ViewController.m write

AVPlayerLayer* layer = (AVPlayerLayer*)self.videoView.layer;

VideoView contains AVPlayerView

AVPlayerView.m write

#import "AVPlayerView.h"
#import <AVFoundation/AVFoundation.h>

@implementation AVPlayerView

+(Class)layerClass{
    return AVPlayerLayer.class;
}

@end

The layerClass method is not called for some reason.
Also, the class returned by (AVPlayerLayer *) self.videoView.layer
AVPresentationVontainerViewLayer.
I want an AVPlayerView class.
How should i fix it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
LionKamado
  • 85
  • 1
  • 1
  • 4

1 Answers1

4

Try this:

    NSURL *url = [NSURL fileURLWithPath:path];
    AVPlayer *player = [AVPlayer playerWithURL:url];
    AVPlayerViewController *AVPlayerVc = [[AVPlayerViewController alloc] init];
    AVPlayerVc.player = player;
    if (AVPlayerVc) {
        [self presentViewController:AVPlayerVc animated:YES completion:^{
            [player play];
        }];
    }

Swift Version:

 let player = AVPlayer(url: YOUR_URL)
 let playerController = AVPlayerViewController()
 playerController.player = player
 present(playerController, animated: true) {
         player.play()
 }
Zouhair Sassi
  • 1,403
  • 1
  • 13
  • 30
  • 1
    Thank you very much. The error has disappeared. However, when the movie is played back, the sound is played but the video is not played. Do I need to change my storyboard connection? – LionKamado Oct 07 '19 at 06:50
  • 2
    Yes i think the video is playing in another view – Zouhair Sassi Oct 07 '19 at 08:38
  • 1
    Thank you.I want to display a video player in an existing AVPlayerView instead of creating a new one. Is this possible? – LionKamado Oct 08 '19 at 08:11
  • i 'don't understand what you want exactly – Zouhair Sassi Oct 08 '19 at 08:54
  • Sorry...Until now, UIView was installed and AVPlayerView was set as Custom Class. And it is going to play a video with the UIView. However, the above code will play full screen on the video player. I want to display a video in UIView. – LionKamado Oct 08 '19 at 09:02
  • take a look to this https://stackoverflow.com/questions/50653779/how-to-play-a-video-in-uiview-swift – Zouhair Sassi Oct 08 '19 at 09:16