Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Objective C - AVPlayer programmatically - play local video, with standard/system skin [closed]

Can anyone help me with code for setting up and playing local videofile, using AVPlayer in Xcode? (using AVPlayerLayer, and AVPlayerViewController) All done programmatically and with standard/system videoskin?

Regards Henning

like image 493
Henning Avatar asked Nov 28 '22 08:11

Henning


2 Answers

AVPlayer *player = [AVPlayer playerWithURL:"YOUR URL"];

// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];

hope this help for you.....

like image 51
Chirag Desai Avatar answered Dec 18 '22 20:12

Chirag Desai


// remote file from server:
NSURL *url = [[NSURL alloc] initWithString:@"https://s3-eu-west-1.amazonaws.com/alf-proeysen/Bakvendtland-MASTER.mp4"];

// create a player view controller
player = [AVPlayer playerWithURL:url];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];

[self addChildViewController:controller];
[self.view addSubview:controller.view];

controller.view.frame = CGRectMake(50,50,500,300);
controller.player = player;
controller.showsPlaybackControls = YES;
player.closedCaptionDisplayEnabled = NO;
[player pause];
[player play];

This is all done in viewDidLoad and its working fine now. I made a subview to present the player.

The only thing that is not working now is player.closedCaptionDisplayEnabled = NO; this is ignored. The video has soft subtitles embedded, and I am able to toggle the subtitles with cc button that is showing. But I am not able to toggle it/control it programmatically?

like image 40
Henning Avatar answered Dec 18 '22 20:12

Henning