Question

I'm creating an radio application in ios. I want to change the volum by using a slider. So I defined an IBAction (- (IBAction)sliderValueChanged : (UISlider *)sender) and drag the Value Changed event of the slider to this IBAction.

This is my IBAction implementation `

 - (IBAction)sliderValueChanged  : (UISlider *)sender 

{

[[MPMusicPlayerController applicationMusicPlayer] setVolume:sender.value];

}`

But when I drag the slider volum is not changing. Any one can tell me what is the problem with this.

Thanks

Was it helpful?

Solution

First declare your musicplayer in .h file.

MPMusicPlayerController *musicPlayer;

in viewDidLoad you can define it.

self.musicPlayer=[MPMusicPlayerController applicationMusicPlayer];

// musicPlayer.volume = 0.5f;

 - (IBAction)sliderValueChanged  : (UISlider *)sender
{
 musicPlayer.volume=sender.value;
}

Try changing volume by giving static value then go for dynamic.

OTHER TIPS

Try use this code

[[MPMusicPlayerController iPodMusicPlayer] setVolume:sender.value];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top