在iphone上没有音量滑块的情况下更改音量 [英] Changing the volume without a volume slider on an iphone

查看:140
本文介绍了在iphone上没有音量滑块的情况下更改音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助。我该如何继续更改应用中的音量。我不想使用音量滑块。相反,我有一个UIImageView,它是一个音量旋钮,我顺时针旋转增加,逆时针旋转减小音量。轮换只是一个动画,我已经完成了那部分。

I need your help. How should I proceed to change the sound volume in my app. I don't want to use a volume slider. Instead I have an UIImageView which is a volume knob, in which I rotate clockwise to increase, and anti clockwise to decrease the sound volume. The rotation is just an animation and I've already done that part.

我需要你的帮助和建议如何增加/减少音量。谢谢

I need your help and advice on how to increase/decrease the volume. Thanks

推荐答案

我会小心地在<$ c上调用 setValue $ c> MPVolumeView 因为除了更新滑块的外观之外它可能不会做任何事情,但不会更新实际的设备音量级别。你需要调用 _commitVolumeChange 这是私有API,可能会拒绝你的应用。

I would be careful calling setValue on an MPVolumeView since it probably won't do anything other than update the appearance of the slider, but not the actual device volume level. You would instead have to call _commitVolumeChange which is private API and will likely get your app rejected.

一个简短的回答如何控制音量:这实际上取决于你试图控制的音量。

A short answer to how to control volume: It really depends on what you're trying to control the volume of.

如果你想要控制应用程序中的每个声音控制那么你可以使用 MPVolumeView 但是您无法以编程方式更改其值。然后,您只能通过触摸移动滑块或使用设备侧面的音量按钮来更改音量。最好的办法是创建一个全局对象,用于存储任何对象在播放声音之前可以读取的音量级别。

If you want a "controls every sound within the app" sort of control then you can use an MPVolumeView but you cannot change it's value programmatically. You would then only be able to change the volume by either moving the slider with a touch or using the volume buttons on the side of the device. The best thing to do is create a global object that stores the volume level which any of your objects can read before they play their sound.

如果是 AVAudioPlayer 对象,你要创建对象并使用 [theAudioPlayerObject setVolume:someFloat]; 其中 someFloat 是介于0.0和1.0之间的值。

If it's an AVAudioPlayer object, you'd create the object and use [theAudioPlayerObject setVolume: someFloat]; where someFloat is a value between 0.0 and 1.0.

如果它是 SystemSound 对象,则无法控制音量。

If it's a SystemSound object, you can't control volume.

如果是 AudioQueue 你要通过 AudioQueueSetParameter改变它

就像我说的..这一切取决于你正在播放声音的

Like I said.. it all depends on how you are playing the sound.

根据评论更新

对于那个特定的例子,你可以这样设置音量:

For that particular example, you would set the volume like this:


添加到AudioStreamer.h文件

Add to the AudioStreamer.h file



- (void)setVolume:(float)Level;




添加到AudioStreamer.m文件

Add to the AudioStreamer.m file



- (void)setVolume:(float)Level
{

    OSStatus errorMsg = AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, Level);

    if (errorMsg) {
        NSLog(@"AudioQueueSetParameter returned %d when setting the volume.", errorMsg);
    }

}




添加到视图控制器中的音量旋钮将在哪里(这是在.m文件中..我只是做了几个UIButton快速,你必须自己做)并设置一个IBAction来改变给定值的体积(你可以传递0.0到1.0作为浮点数)

Add to the view controller for where the volume knob will be (this goes in the .m file.. i just did this as a couple UIButtons real quick, you'll have to do your own) and set up an IBAction to change the volume for a given value (you can pass in 0.0 thru 1.0 as a float)



- (IBAction)volumeUp:(id)sender
{

    [streamer setVolume:1.0];

}

- (IBAction)volumeDown:(id)sender
{

    [streamer setVolume:0.0];

}

这篇关于在iphone上没有音量滑块的情况下更改音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆