更改设备音量

时间:2012-02-10 12:02:13

标签: iphone objective-c ios ipod

我正在开发一个Iphone / Ipod应用程序,我正在使用AVAudioPlayer。我通过滑块改变音量,这是正常的,但现在我必须通过按设备加号和减号按钮而不是自己更改滑块来更改(增加/减少)滑块。当我按下设备的加/减按钮时,不知道控制在哪里?有谁知道,随时提供帮助。

3 个答案:

答案 0 :(得分:2)

  

如何访问硬件音量控制器?

     

全球系统卷(包括应用程序的卷)由iPhone OS处理,应用程序无法访问。

这是链接,请仔细阅读here 希望它能帮助你:))

答案 1 :(得分:1)

这个问题对我来说并不完全清楚,但是当系统容量发生变化时,您似乎想要通知?如果是这样,这是可能的,我希望我能正确理解你的问题。如下:

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(volumeChanged:)
     name:@"AVSystemController_SystemVolumeDidChangeNotification"
     object:nil];
}

- (void)volumeChanged:(NSNotification *)notification
{
    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
     floatValue];

    // Do stuff with volume
}

我从here,Sandy的回答中抓住了这个。

答案 2 :(得分:0)

大满贯并感谢所有人!我搜索过它。这适用于MPMusicPlayer,但不适用于AVAudioPlayer。 你可以做到。

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

但这不适用于AVAudioPlayer,

AVAudioPlayer *_audioController = [AVAudioPlayer iPodMusicPlayer];