獲取系統當前音量 和 監聽系統音量 ios


-(float) getVolumeLevel {MPVolumeView*slide =[MPVolumeViewnew];UISlider*volumeViewSlider;for(UIView*view in[slide subviews]){if([[[view class] description] isEqualToString:@"MPVolumeSlider"]){ volumeViewSlider =(UISlider*) view;}}float val =[volumeViewSlider value];[slide release];return val;}

That should get you the current volume level. 1 is max volume, 0 is no volume. Note: no UI elements need to be displayed for this to work. Also note current volume level is relative to headphones or speakers (meaning, the two volume levels are different, and this gets you whichever the device is currently using. This doesn't answer your question regarding receiving notifications of when volume changes.

 

 

 

AVSystemController

+ (id)sharedAVSystemController;

- (void)getActiveCategoryVolume:(float*)outVolume andName:(NSString**)outName;

Returns the volumn and name of the active category. Tells you whether headphones are plugged in.

Notifications

Sends a AVSystemController_HeadphoneJackIsConnectedDidChangeNotification notification when the user plus in or unplugs headphones.

Sends a AVSystemController_SystemVolumeDidChangeNotification notification when the system volume has changed (via up/down buttons, mute switch, or programatically)

 

        [[NSNotificationCenterdefaultCenter] addObserver:self

                                                 selector:@selector(volumeChanged:)

                                                     name:@"AVSystemController_SystemVolumeDidChangeNotification"

                                                   object:nil];

 

-(void)volumeChanged:(NSNotification *)notification {  [volumeViewSlider setValue:[[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]]; }

 

 

 

-(void)volumeChanged:(NSNotification *)notification {  [volumeViewSlider setValue:[[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]]; }
 
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM