Objective-C 静音和取消静音的方法
我有点卡住了,我正在尝试编写一种方法,当按下按钮时;将获取 iTunes 的当前音量,将音量存储为声明为 x 的 int 。然后使 iTunes 音量等于 0,这实际上会使 iTunes 音量静音,但如果再次按下按钮,我希望 iTunes 音量返回到 int x,这实际上会取消 iTunes 音量静音并将其恢复到原始状态体积。
到目前为止,这就是我所拥有的:
- (IBAction)muteAndUnmute:(id)sender {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
int x;
x = [iTunes soundVolume];
if ([iTunes soundVolume] > 0 ) {
[volumeSlider setIntValue:0];
[iTunes setSoundVolume:[volumeSlider intValue]];
[volumeLabel setIntValue:[volumeSlider intValue]];}
}
任何帮助将不胜感激,我认为这很容易做到,但我无法理解它,提前感谢,萨米。
I'm a little stuck, i'm trying to write a method which when a button is pressed; will get the current volume of iTunes, store the volume as an int declared as x. Then make the iTunes volume equal to 0, which will essentially mute the iTunes volume, but then i want the iTunes volume to return to the int x if the button is pressed again, which will essentially unmute the iTunes volume and restore it to the original volume.
Here's what i have so far:
- (IBAction)muteAndUnmute:(id)sender {
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
int x;
x = [iTunes soundVolume];
if ([iTunes soundVolume] > 0 ) {
[volumeSlider setIntValue:0];
[iTunes setSoundVolume:[volumeSlider intValue]];
[volumeLabel setIntValue:[volumeSlider intValue]];}
}
Any help would be much appreciated, i think it's quite easy to do but just can't get my head around it, thanks in advance, Sami.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让你的体积值(vol)作为类变量而不是本地变量,然后
make your volume value (vol) as class variable and not local, then
你可以使用这个:
you can use this: