iOS 设置系统音量和监听系统音量变化
生活随笔
收集整理的這篇文章主要介紹了
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];}?
轉載于:https://www.cnblogs.com/Milo-CTO/p/4581662.html
總結
以上是生活随笔為你收集整理的iOS 设置系统音量和监听系统音量变化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 动态规划(五) 最大连续子序列和(Max
- 下一篇: 编程实现背包的递归和非递归两种解法_算法