问题
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