zoukankan      html  css  js  c++  java
  • iOS 设置系统音量和监听系统音量变化

    很简单的调用 

    首先在工程引入MediaPlayer.framework

    #import <MediaPlayer/MediaPlayer.h>

    1. 获取系统音量

    // 获取系统音量
    MPVolumeView *volumeView = [[MPVolumeView alloc] init];
    
    UISlider *volumeViewSlider= nil;
    
        for (UIView *view in [volumeView subviews]){
    if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
    volumeViewSlider
    = (UISlider*)view;
    break; } } float systemVolume = volumeViewSlider.value;

    2.监听方法

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
    - (void)volumeChanged:(NSNotification *)notification
    {
         [notification.userInfo[@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
    
    }

     3.记得销毁哦

    - (void)dealloc
    {
    
        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
    
    }
  • 相关阅读:
    13.6 线程通信
    13.5 线程同步
    13.4 控制线程
    13.3 线程的生命周期
    13.2 线程的创建与启动
    13.1 线程概述
    12.10 NIO.2的功能和用法
    bs4
    mysql基本命令
    HDU-1021 Fibonacci Again
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/4581662.html
Copyright © 2011-2022 走看看