Pregunta

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

¿Fue útil?

Solución

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.

Otros consejos

Try use this code

[[MPMusicPlayerController iPodMusicPlayer] setVolume:sender.value];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top