zoukankan      html  css  js  c++  java
  • 获取系统当前音量 和 监听系统音量 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]]; }
     
     
     
     
     
  • 相关阅读:
    libxml2 使用教程【转】
    c++实现Xml和json互转【转】
    C++中JSON的使用详解【转】
    Libxml2函数及使用方法概述【转】
    首个threejs项目-前端填坑指南【转】
    如何使用chrome自带的Javascript调试工具 【转】
    require.js 最佳实践【转】
    Cesium中导入三维模型方法(dae到glft/bgltf) 【转】
    华为ap3010DN-V2刷出胖AP并配置接入POE交换机实现上网
    k8s cronjob设置作业失败后退出不重复执行
  • 原文地址:https://www.cnblogs.com/leevaboo/p/2923628.html
Copyright © 2011-2022 走看看