Khalid Usman
Khalid Usman

Reputation: 1282

Changing Device Volume

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.

Upvotes: 2

Views: 1825

Answers (3)

Khalid Usman
Khalid Usman

Reputation: 1282

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];

Upvotes: 0

Paul
Paul

Reputation: 11

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.

Upvotes: 1

Zaksh
Zaksh

Reputation: 963

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 :)

Upvotes: 2

Related Questions