문제

I'm using an AVPlayer to play various medias. I redesigned the whole player interface and I added a MPVolumeView to control output level. It works just fine, either with the slider or with the volume buttons (yje output volume is changed), but the user gets no visual indication that the volume is changing. When using the Apple's built in Video App, when you change the output volume using buttons, there is a nice hud indicating the current volume : how can I make it appear? Thanks.

도움이 되었습니까?

해결책

As a matter of fact, it seems that the VolumeView blocks the delivery of notifications to the system. I had to use AudioSessionAddPropertyListener to make it work like this

AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange,
                                         audioRouteChangeListenerCallback,
                                         self);

and the callback

// detecting outplugg of the iPhone
void audioRouteChangeListenerCallback (void                      *inClientData,
                                   AudioSessionPropertyID    inID,
                                   UInt32                    inDataSize,
                                   const void                *inData)
{
    CFDictionaryRef routeChangeDictionary = inData;

    CFNumberRef routeChangeReasonRef =
    CFDictionaryGetValue (routeChangeDictionary,
                      CFSTR (kAudioSession_AudioRouteChangeKey_Reason));

    SInt32 routeChangeReason;

    CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);

    if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
    {
        // Headset is unplugged..
        [(VideoPlayerViewController*)inClientData pause];
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top