使用MPMusicPlayerController进行音量控制

时间:2015-08-17 09:07:50

标签: ios volume mpmusicplayercontroller

我使用MPMusicPlayerController使用我的滑块更改系统音量:

-(void)viewDidLoad{
     MPMusicPlayerController musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
}

然后我实现了以下方法来改变声音:

-(IBAction)sliderValueChanged:(UISlider *)sender{
    [musicPlayer setVolume:  sender.value];
}
- (void)volumeChanged:(NSNotification *)notification
{
    float volume =[[[notification userInfo]   objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]floatValue];
    [self.volumSeekbar setValue:musicPlayer.volume];
}

当我用导引头改变音量时,它显示了系统音量控制器,有什么方法可以阻止显示它吗?

编辑:MPVolume默认图像质量好,但有点大! enter image description here

1 个答案:

答案 0 :(得分:2)

这些是我使用的图像 - 我只包括1x尺寸 - 拇指是54 x 30

[self.mpVolumeView setMinimumVolumeSliderImage:[UIImage imageNamed:@"master_volume_bar"] forState:UIControlStateNormal];
[self.mpVolumeView setMaximumVolumeSliderImage:[UIImage imageNamed:@"grey_volume_bar"] forState:UIControlStateNormal];
[self.mpVolumeView setVolumeThumbImage:[UIImage imageNamed:@"volume_thumb"] forState:UIControlStateNormal];

master_volume_bar

grey_volume_bar

volume_thumb