MPVolumeView, avoid displaying "No available volume"

I have a project with MPVolumeView. It is configured and it works, the only thing is that when the device is turned off, the text "No Volume Available"appears instead MPVolumeView. I would prefer the slider to MPVolumeViewbe turned off when the device is turned off.

The volumeView identifier is initialized in the view volumeBounds, with this rating.

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:volumeBounds.bounds] autorelease];
[volumeBounds addSubview:volumeView]; 
[volumeView sizeToFit];

Thank:)

If you are interested in helping me with something else, check out this question.

+3
source share
2 answers

AudioServices . , MPVolumeSlider UISlider . .

AudioSessionAddPropertyListener( kAudioSessionProperty_CurrentHardwareOutputVolume , ... );

kAudioSessionProperty_AudioRouteChanged .

MPVolumeView, UISlider. , , , .

Edit:

. , - :

void MyPropertyListener ( void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData );

void MyPropertyListener ( void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData ) {
  if ( inID == kAudioSessionProperty_CurrentHardwareOutputVolume ) {
    Float32 volume = *(Float32 *)inData;
    [(MyDelegateClass *)inClientData hardwareVolumeChanged:volume];
  }
}

AudioSessionAddPropertyListener( kAudioSessionProperty_CurrentHardwareOutputVolume ,
  MyPropertyListener , aDelegateInstance );
+3

.

Objective-C:

[UILabel appearanceWhenContainedIn: [MPVolumeView class], nil].textColor = [UIColor clearColor];

Swift:

UILabel.appearanceWhenContainedWithin([MPVolumeView.self]).textColor = UIColor.clearColor()

appearanceWhenContainedWithin: WhenContainedIn Swift

" " UISlider, MPVolumeView UISlider.

AVPlayer volume, :

.

AVAudioSession outputVolume, :

; MPVolumeView.

( ) .

+1

Source: https://habr.com/ru/post/1745331/


All Articles