hgpl
hgpl

Reputation: 869

Sound controls of device related to app

In my app I have some sounds.To use these sounds I used AVFoundation,MediaPlayer,AudioToolbox frameworks.The application is running fine in device. But the problem I am facing is when I decrease or increase my device volume then app sound is not effected by that.I want to control my app sound's volume by controlling device volume. Can anybody please tell me how can I do this? Please help. Thanks in advance.

Upvotes: 0

Views: 155

Answers (1)

Volodymyr B.
Volodymyr B.

Reputation: 3441

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

and did you start the audio session with AudioSessionSetActive

And suggest you first take the sample code which Apple provided (I use 'aurioTouch'). Maybe it could help you to find out what happened.

Upvotes: 1

Related Questions