Autoplay for vimeo videos in iOS

583 Views Asked by At

i have code with youtube auto play , but now requirement is to play Vimeo videos in autoplay. I used to write code in objective c can u give any example codes fit to this requirement? note:i used third party tool name as "MPMoviePlayerViewController"

1

There are 1 best solutions below

0
On

The MPMoviePLayerViewController class has been deprecated in iOS 9. Apple recommend using AVPLayerViewController instead - it works well with local and remote URLs.

Here's how you can use it in Objective-C:

// grab your remote URL
NSURL *videoURL = [NSURL URLWithString:@"http://domain.com/video.mp4"];

// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];

// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];

// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;

You must import AVFoundation and AVKit into your class for this to be successful.