0

I want to change volume of played movie. As I've understand that I have to use MPVolumeView, and the next code perfectly worked in ios 6.1 (tested on ipod touch 4g), but does not work on ios 8.1 (simulator Version 8.1 (550.3)) - volume slider does not appear. Please help what have I missed?

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController ()

@property (retain, nonatomic) MPMoviePlayerController *player;
@property (retain, nonatomic) MPVolumeView *volumeView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSURL *movieUrl = [[NSBundle mainBundle] URLForResource:@"IMG_0001" withExtension:@"MOV"];
    self.player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
    self.player.view.frame = self.view.bounds;

    // Here is where you set the control Style like fullscreen or embedded
    self.player.controlStyle = MPMovieControlStyleEmbedded;
    self.player.scalingMode = MPMovieScalingModeAspectFit;
    self.player.allowsAirPlay = YES;
    [self.view addSubview:self.player.view];

    [self.player prepareToPlay];
    [self.player play];

    self.volumeView = [ [MPVolumeView alloc] init];
    [self.volumeView setShowsVolumeSlider:YES];
    [self.volumeView setShowsRouteButton:YES];
    self.volumeView.frame = CGRectMake(0, 0, self.view.bounds.size.width, 30);
    // show volume view border
    self.volumeView.layer.borderColor = [[UIColor redColor] CGColor];
    self.volumeView.layer.borderWidth = 1.0f;

    // next 6 lines - is my try to add slider images, but no luck again
    UIImage *sliderThumbImage = [UIImage imageNamed:@"sliderthumb.png"];
    UIImage *sliderMinTrackImage = [UIImage imageNamed:@"slidermintrack.png"];
    UIImage *sliderMaxTrackImage = [UIImage imageNamed:@"slidermaxtrack.png"];
    [self.volumeView setMinimumVolumeSliderImage:sliderMinTrackImage forState:UIControlStateNormal];
    [self.volumeView setMaximumVolumeSliderImage:sliderMaxTrackImage forState:UIControlStateNormal];
    [self.volumeView setVolumeThumbImage:sliderThumbImage forState:UIControlStateNormal];

    [self.view addSubview:self.volumeView];
}

@end

P.S. xCode 6.1

slavik
  • 1,341
  • 2
  • 11
  • 16

1 Answers1

4

Sadly on a simulator the volume bar does not show. You must test on a device.

  • Apple should really provide at least a fake one for the simulator, because I cannot test my layouts except on the devices that I actually own. Which means you need at least three iPhones (6+, 6 and older) and one iPad. – gnasher729 May 14 '15 at 12:47