多媒体音量控制
2015-05-26 00:00
1011 查看
方案一:
MPMusicPlayerController
// This property is deprecated -- use MPVolumeView for volume control instead.
该方法在7.0后已经标记为废除
获取音量
[MPMusicPlayerController applicationMusicPlayer].volume
设置音量
[[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolume];
使用该方法改变音量时,会出现系统的音量调节的View, 如果要隐藏,需要实例化一个MPVolumeView,然后将其的加入当前的view中,并将其的位置设置在不可见的地方(可以是超出屏幕的位置,注意使用hidden是无效的)。
方案二:
MPVolumeView (需要导入<MediaPlayer/MPVolumeView.h>)
注意:需要使用真机,模拟器无法看到
MPVolumeView m_volumeView = [[MPVolumeView alloc]initWithFrame:CGRectMake(10, 10, 200, 30)];
[self.view addSubview:m_volumeView];
调节滑动条会自动修改系统音量。
监听系统音量变化
使用通知:AVSystemController_SystemVolumeDidChangeNotification 对系统的音量进行监听。
注册通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
通知回调处理
-(void) volumeChanged:(NSNotification *)notification
{
float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
if(volume == m_currentVolume)
{
return;
}
m_currentVolume = volume;
// TODO
}
删除通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
MPMusicPlayerController
// This property is deprecated -- use MPVolumeView for volume control instead.
该方法在7.0后已经标记为废除
获取音量
[MPMusicPlayerController applicationMusicPlayer].volume
设置音量
[[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolume];
使用该方法改变音量时,会出现系统的音量调节的View, 如果要隐藏,需要实例化一个MPVolumeView,然后将其的加入当前的view中,并将其的位置设置在不可见的地方(可以是超出屏幕的位置,注意使用hidden是无效的)。
方案二:
MPVolumeView (需要导入<MediaPlayer/MPVolumeView.h>)
注意:需要使用真机,模拟器无法看到
MPVolumeView m_volumeView = [[MPVolumeView alloc]initWithFrame:CGRectMake(10, 10, 200, 30)];
[self.view addSubview:m_volumeView];
调节滑动条会自动修改系统音量。
监听系统音量变化
使用通知:AVSystemController_SystemVolumeDidChangeNotification 对系统的音量进行监听。
注册通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
通知回调处理
-(void) volumeChanged:(NSNotification *)notification
{
float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
if(volume == m_currentVolume)
{
return;
}
m_currentVolume = volume;
// TODO
}
删除通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
相关文章推荐
- [学习记录]多媒体音量控制setVolumeControlStream(int streamType)
- 多媒体音量控制setVolumeControlStream(int streamType)
- android setVolumeControlStream多媒体音量控制介绍
- Android---控制多媒体应用程序的音量和播放
- 小问题一枚,键鼠支持多媒体控制的骚年,无法控制音乐、音量等的解决方法
- 多媒体音量控制setVolumeControlStream(int streamType)
- Android---控制多媒体应用程序的音量和播放
- android开发笔记之多媒体—AudioManager(控制音量)
- 多媒体音量控制setVolumeControlStream(int streamType)
- 多媒体音量控制setVolumeControlStream(int streamType)
- 多媒体音量控制setVolumeControlStream(int streamType)
- 管理媒体播放(1)控制应用程序的音量和播放
- Android始终控制媒体音量
- c# Winform 获取麦克风音量 控制麦克风音量大小 (自用笔记未测试)
- 大二上学期Linux课程设计(基于qt的音量控制管理器)
- android音量控制
- android-----音乐播放器的音量控制功能(开发)
- android 音量控制 流程梳理
- Android 系统音量控制
- windows7系统使用(合成器)单独控制各个程序的音量