views:

75

answers:

1

i am creating a application in which sound is played when a button is pressed and using a UISlider with which volume can be adjusted.Sometimes the volume of sound is too high and sometimes its too low even after increasing the volume of iphone to the full.How can i keep the volume to always high?? any possible way to integrate system volume with slider volume?? Using MPVolumview will get my app rejected i guess.. the code i am using on button touch is this

NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/sound.mp3"];
NSLog(@"Path to play: %@", resourcePath);



player = [[AVAudioPlayer alloc] initWithContentsOfURL:
          [NSURL fileURLWithPath:resourcePath] error:&err];

    player.delegate = self;
    [player play];
    player.volume=.50;
    player.numberOfLoops=-10;

-(IBAction)slidervaluechanged 
{ player.volume=slider.value; }

}

A: 

Hemant,

The maximum volume you can have is when player.volume is equal to 1.0 (so long as the ringer volume is all the way maximum as well).

If the ringer volume is not at maximum, you can only go as high as whatever it is at by again using the value of 1.0

However, you could implement the MPVolumeView (I'm almost positive, as Pandora does it) and then you use that slider in your app instead. Then you can just set player.volume always equal to 1.0 and let the slider change the ringer volume.

More information on if you want to use MPVolumeView: http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html and http://stackoverflow.com/questions/2795567/how-do-you-implement-an-mpvolumeview

I may be wrong, but I think Apple allows MPVolumeView if you use it as-is. They say in the class reference that it now changes the device ringer volume when you move the slider (which it didn't used to and that's why people were having to access private API to do). I'm going to try and implement it on my next update here in a week, so if I get rejected, I'll come back here and update this post to let everyone know.

iWasRobbed