7

I have implemented this streamer(https://github.com/DigitalDJ/AudioStreamer) inside my app and it runs fantastic, however it doesn't have volume controls implemented, anyone have tips how to get started with volume slide or something?

I was looking trough some similar questions :

Didn't find any of these useful to answer to my question, how to change volume(up/down) and of course hook it to some kind of control i.e. slider, any help is appreciated

Community
  • 1
  • 1
London
  • 14,986
  • 35
  • 106
  • 147

2 Answers2

21

make sure you add the MediaPlayer framework to your project

you have to define a view in your .h file to put the slider in in this case "viewVolume"

INFO: THIS WONT WORK IN A SIMULATOR ONLY ON A REAL DEVICE.

#import <MediaPlayer/MediaPlayer.h>

- (void)showTheVolumeSlider {

    MPVolumeView *volumeViewSlider = [[MPVolumeView alloc] initWithFrame:viewVolume.bounds] ;
    [viewVolume addSubview:volumeViewSlider];
    [volumeViewSlider sizeToFit];

}

this code is using ARC.

this code wil also work:

musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
    musicPlayer.volume = slider.value;

but if you want to use this you have to make an system that updates the slider as the volume of the device is adjusted from an other place

this wil work for updating the volume but i don't know if it's the best way

  timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateSound) userInfo:nil repeats:YES];

this to update the UISlider:

- (void)updateSound {

    musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
    slider.value = musicPlayer.volume;
    // value from 0.0 to 1.0

}
Floris497
  • 1,406
  • 12
  • 18
  • I know this is an old question, but on the off chance you're around, is there any way to set an existing UISlider to be the MPVolumeView? – Ruben Martinez Jr. Feb 09 '14 at 08:21
  • Ruben Martinez Jr. - use the second code block, but it gives you feedback in the form of the volume overlay the same a using the volume controles at the side of your device, iirc. – Floris497 Feb 10 '14 at 08:18
9

You can use MPVolumeView. This gives you a UISlider that controls the volume.

edc1591
  • 10,146
  • 6
  • 40
  • 63