0

I want get the current value of my iphone from my audio player in objective c. But I can't get this because is deprecated.

MPMusicPlayerController *musicPlayer;
musicPlayer.volume //This is deprecated

There are some alternatives?

Willeke
  • 14,578
  • 4
  • 19
  • 47
user3745888
  • 6,143
  • 15
  • 48
  • 97

1 Answers1

0

As written in the developer docs you should use the VolumeView (Seen here)
Because it is a view, you cannot get the current value. I'm not sure, but maybe this code works (not tested):

MPVolumeView* volumeView = [[MPVolumeView alloc] init];
for (UIView *view in [volumeView subviews]){
    if([view isKindOfClass:[UISlider class]]) {
        UISlider *slider = (UISlider*) view;
        CGFloat volume = slider.value; // this is the current volume
    }
}

If this does not work, you can set the volume of you application by setting

slider.value = 1.0f;

in the for loop.

tmiedema
  • 174
  • 7