-(void)setSystemVolum:(float)newVolume {
MPVolumeViewslide =[MPVolumeView new];
static UISlidervolumeViewSlider = nil;
for(UIViewview in[slide subviews]) {
if([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider =(UISlider) view;
}
}
volumeViewSlider.value = newVolume;
// [volumeViewSlider setValue:newVolume animated:YES];
NSLog(@"newVolume==%@",@(newVolume));
if (newVolume == 0.0) {
[volumeButton setBackgroundImage: [UIImage imageNamed:@"movie_btn_vol_off_normal@2x.png"] forState:UIControlStateNormal];
[volumeButton setBackgroundImage:[UIImage imageNamed:@"movie_btn_vol_off_pressed@2x.png"] forState:UIControlStateHighlighted];
[volumeButton setBackgroundImage:[UIImage imageNamed:@"movie_btn_vol_off_pressed@2x.png"] forState:UIControlStateSelected];
}else {
[volumeButton setBackgroundImage: [UIImage imageNamed:@"movie_btn_vol_on_normal@2x.png"] forState:UIControlStateNormal];
[volumeButton setBackgroundImage:[UIImage imageNamed:@"movie_btn_vol_on_pressed@2x.png"] forState:UIControlStateHighlighted];
[volumeButton setBackgroundImage:[UIImage imageNamed:@"movie_btn_vol_on_pressed@2x.png"] forState:UIControlStateSelected];
}
if ([UIDevice currentDevice].systemVersion.floatValue >= 13.0) {
// 适配iOS13,音量条修改
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
if (([musicPlayer respondsToSelector:@selector(setVolume:)])) {
//消除警告
pragma clang diagnostic push
pragma clang diagnostic ignored "-Wdeprecated-declarations"
[musicPlayer setVolume:newVolume];
pragma clang diagnostic pop
}
}
}
网友评论