ios - MPVolumeView 在 ios 8 中不起作用

标签 ios objective-c mpvolumeview

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

#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

附言xCode 6.1

最佳答案

遗憾的是在模拟器上音量条不显示。您必须在设备上进行测试。

关于ios - MPVolumeView 在 ios 8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28261830/

相关文章:

ios - 内存管理 - 如何在不创建新实例的情况下显示已实例化的 ViewController

ios - 使用 UIViewController 子类的子类和 UIView 子类的子类

ios - 具有关系实体保存的新实体导致重复错误 - CoreData Swift

ios - Swift 类未添加到基于 Objective-C 的项目中

iphone - 搜索只匹配开头的单词

iphone - 从应用程序 (AVPlayer - MPVolumeView) 在 Apple TV 上播放元数据

ios - 如何获取所有包含特定字符串的网址?

user-interface - 使用屏幕音量 slider 时不应出现音量 UI - iOS

ios - 将 MPVolumeView 添加到底部工具栏

ios - 如何在滚动时保持 UICollectionView Cells 的背景颜色不变?