本文介绍了iOS 7:不推荐使用MPMusicPlayerController卷。如何更改设备音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MPMusicPlayerController setVolume

MPMusicPlayerController setVolume is deprecated since iOS 7

有没有其他方法可以更改系统音乐音量?最好没有用户交互。
其重要特性:从AppStore自动增加任何闹钟的音量。

Is there any other way to change system music volume? Preferably without user interaction.Its important feature: to increase volume automatically for any alarm clock from AppStore.

推荐答案

准确回答你的问题:
是的还有其他方法可以在没有用户交互的情况下更改系统音量。

To answer you question exactly:Yes there is other way to change system volume without user interaction.

直到最近我才认为使用MPVolumeView以编程方式更改音量只能使用私有API 。但我刚刚验证过,更改volumeSlider的值和伪滑块的touchUP事件有效:

Until recent times I used to think that changing volume using MPVolumeView programmatically is possible only using private API. But I have just verified, that changing the value of volumeSlider and faking slider's touchUP event works:

MPVolumeView* volumeView = [[MPVolumeView alloc] init];

//find the volumeSlider
UISlider* volumeViewSlider = nil;
for (UIView *view in [volumeView subviews]){
    if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
        volumeViewSlider = (UISlider*)view;
        break;
    }
}

[volumeViewSlider setValue:1.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];

(当滑块收到touchUP事件时,它将调用 _commitVolumeChange 方法本身,它将改变系统音量)

(When slider receives touchUP event, it will invoke _commitVolumeChange method on itself, which will change the system volume)

这篇关于iOS 7:不推荐使用MPMusicPlayerController卷。如何更改设备音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 08:24