I am able to run the video, but I am not able to see the control buttons like pause and the slider to interact with the video. Similar query is asked (see here) but I do not follow the answer.
Asked
Active
Viewed 1.2k times
6

Community
- 1
- 1

Utsav Dusad
- 2,139
- 4
- 31
- 52
-
1I would suggest to use awesome tutorial & demo available in [apple documentation](https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html) It has all the controls you are looking for – Dipen Panchasara Apr 07 '16 at 08:19
-
1Thank you Dipen, I had seen this example and it is very useful one but it doesn't use AVPlayerViewController which uses system playback controls. – Utsav Dusad Apr 07 '16 at 08:38
-
its not AVPlayerViewController, its pure `AVPlayer` example. Please do check again. – Dipen Panchasara Apr 07 '16 at 08:41
-
1Yes thats what I meant, it is pure AVPlayer example. I want a one with system playback controls ( done using AVPlayerViewCntroller ) which is very well explained in [WWDC 2014](https://developer.apple.com/videos/play/wwdc2014/503/) – Utsav Dusad Apr 07 '16 at 08:45
-
Then you should use `MPMoviePlayerController` thats the only one which gives your desired result. – Dipen Panchasara Apr 07 '16 at 08:53
-
`MPMoviePlayerController` is deprecated from iOS9.0. I think `AVPlayerViewController` does the same job as the `MPMoviePlayerController` does. – Utsav Dusad Apr 07 '16 at 08:57
1 Answers
5
I got the answer with description. See here. To display system playback controls like play, pause button etc. we need AVPlayerViewController. Below is the implementation in Objective-C.
@interface ViewController ()
@property (strong,nonatomic) AVPlayerViewController *avPlayerViewController;
@property (strong,nonatomic) AVPlayer *avPlayer;
@end
- (void)viewDidLoad {
[super viewDidLoad];
//URL for the file. It can be over HTTP or local file URL.
NSURL *folderURL=[NSURL fileURLWithPath:uploadFolderLocation];
NSURL *movieURL=[folderURL URLByAppendingPathComponent:@"video.mp4"];
self.avPlayer = [AVPlayer playerWithURL:movieURL];
self.avPlayerViewController=[[AVPlayerViewController alloc]init];
self.avPlayerViewController.player=self.avPlayer;
}
- (IBAction)playButtonTapped:(id)sender {
//Trigger the video to play
//AVPlayer object can direct its visual output to AVPlayer. AVPlayerVC is a AVPlayerViewController. You can add it via objects in bottom-right corner.
AVPlayerVC *avPLayerVC=[[AVPlayerVC alloc] init];
avPLayerVC.player=self.avPlayer;
[self addChildViewController:self.avPlayerViewController];
[self.view addSubview:self.avPlayerViewController.view];
self.avPlayerViewController.view.frame=self.view.frame;
[self.avPlayerViewController.player play];
}

Utsav Dusad
- 2,139
- 4
- 31
- 52