Changing Device Volume

空扰寡人 提交于 2019-12-12 19:22:39

问题


I am developing an Iphone/Ipod Application, in which I am using AVAudioPlayer. I am changing volume of audio through slider, which works correctly, but now I have to change(increase/decrease) slider by pressing the device plus and minus button instead of changing slider by myself. When I press plus/minus button of device, don't know where the control goes? Does anybody know, feel free to help.


回答1:


How do I access the hardware volume controller?

Global system volume, including your application's volume, is handled by iPhone OS and is not accessible by applications.

Here is link kindly read it here Hope it will help you :)




回答2:


The question isn't entirely clear to me, but it seems you're wanting a notification when the system volume changes? If so, this is possible, I hope I understand your question correctly. How about the following:

- (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
}

I grabbed this from here, Sandy's answer.




回答3:


Slam and thanks all! I have searched on it. This is valid for MPMusicPlayer, but not for AVAudioPlayer. You can do it.

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

But not this for AVAudioPlayer,

AVAudioPlayer *_audioController = [AVAudioPlayer iPodMusicPlayer];


来源:https://stackoverflow.com/questions/9227435/changing-device-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!