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;
Floris497
source share