美文网首页
oc 音量控制

oc 音量控制

作者: hypercode | 来源:发表于2021-05-20 14:59 被阅读0次

    -(void)setSystemVolum:(float)newVolume {
    MPVolumeViewslide =[MPVolumeView new];
    static UISlider
    volumeViewSlider = 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

        }
    }
    

    }

    相关文章

      网友评论

          本文标题:oc 音量控制

          本文链接:https://www.haomeiwen.com/subject/qqxbjltx.html