简体   繁体   English

AVAudioPlayer setVolume-如何?

[英]AVAudioPlayer setVolume - How?

Does anyone know the best way to mute game sounds on my app. 有谁知道在我的应用上静音游戏声音的最佳方法。

I am currently using SystemSoundID which I know cannot have the volume adjusted and need to move to AVAudioPlayer. 我目前正在使用SystemSoundID,我知道它无法调节音量,需要移动到AVAudioPlayer。

Ideally I need a settings page where the volume can be changed and the volume level saved so when coming back out or leaving and re-opening the app it remembers to volume level? 理想情况下,我需要一个设置页面,可以在其中更改音量并保存音量级别,以便退出或退出并重新打开应用时还记得音量级别吗?

I have tried it various ways using AVAudioPlayer but had no success at present and am receiving some bad reviews for my app for people saying they hate that they cant control the game volume... HELP!! 我已经使用AVAudioPlayer尝试了多种方式,但是目前还没有成功,对于我的应用程序,我收到了一些不好的评价,因为人们说他们讨厌他们无法控制游戏的音量……帮助!

for AVAudioPlayer you can use this code to mute volume 对于AVAudioPlayer,您可以使用此代码使音量静音

in .h file 在.h文件中

@interface ViewController : UIViewController
{
    BOOL muted;
}

and in .m file 并在.m文件中

- (void)viewDidLoad
{
    [super viewDidLoad];
    muted = NO;
}

- (IBAction)speakerOnOff:(id)sender
{

    if (muted) {
        muted = NO;
        [player setVolume:1.0];
    } else {
        muted = YES;
        [player setVolume:0.0];
    }
}

this code is from this great answer. 这段代码来自这个好答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM