0

我想改变播放电影的音量。据我了解,我必须使用 MPVolumeView,下一个代码在 ios 6.1 中完美运行(在 ipod touch 4g 上测试),但在 ios 8.1 上不起作用(模拟器版本 8.1 (550.3)) - 音量滑块不出现. 请帮助我错过了什么?

#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

PS xCode 6.1

4

1 回答 1

4

可悲的是,在模拟器上,音量条没有显示。您必须在设备上进行测试。

于 2015-05-14T12:37:56.880 回答