gpt4 book ai didi

ios - MPVolumeView 在 ios 8 中不起作用

转载 作者:行者123 更新时间:2023-11-28 18:59:05 27 4
gpt4 key购买 nike

我想改变播放电影的音量。据我所知,我必须使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com