IOS: access audio device hardware audio device

I applied this streamer ( https://github.com/DigitalDJ/AudioStreamer ) inside my application and it works fantastically, however it does not have built-in volume controls, who has tips on how to get started with the volume slide?

I was looking for some similar questions:

I did not find anything useful to answer my question, how to change the volume (up / down) and, of course, transfer it to some control, i.e. slider, any help would be appreciated

+7
source share
2 answers

make sure you add the MediaPlayer framework to your project

you need to define the view in your .h file to insert the slider in this case "viewVolume"

INFO: THIS IS AN ADVANCED WORK IN THE 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 uses ARC.

this code also works:

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

but if you want to use this, you need to create a system that updates the slider when the volume of the device is configured from another location.

this wil works to update the volume but i don't know if it is the best

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

to update UISlider:

 - (void)updateSound { musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; slider.value = musicPlayer.volume; // value from 0.0 to 1.0 } 
+21
source

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

+9
source

All Articles