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

Était-ce utile?

La 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.

Autres conseils

Try use this code

[[MPMusicPlayerController iPodMusicPlayer] setVolume:sender.value];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top