Search code examples
iosobjective-cios7mpmovieplayercontroller

How do I add a volume control in my MPMoviePlayerController instance


The below is the code which opens a video on a button press. Everything is fine but I want to add a volume control for my video player. Is there a default feature from the MPMoviePlayerController that I can just enable, or do I have to use the slider from the objects library , drag and drop it, and the adjust the volume according to the slider value?

NSString *url = [[NSBundle mainBundle] pathForResource:@"space-time" ofType:@"mp4"];


moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[self.view addSubview:moviePlayer.view];

moviePlayer.fullscreen = YES;


[moviePlayer play];

Solution

  • to add a volume view use this code make a uiview in your viewcontroller of about 200width by 30height, drop outlet for that view (view1) after that

    MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:self.view1.bounds] ;
     [self.view1 addSubview:volumeView];
    

    volume slider will show up in that view1