我是靠谱客的博主 娇气烧鹅,这篇文章主要介绍android音量控件苹果主题,iOS自定义音量显示控件,现在分享给大家,希望可以做个参考。

需求分析:

观看视频时,点击音量按键,屏蔽系统音量弹窗,显示自定义的音量控件,提高应用观看体验

步骤:

1.创建MPVolumeView

MPVolumeView *volumeView = [[MPVolumeView alloc]initWithFrame:CGRectMake(-100, -100, 10, 10)];

[self.view addSubview:volumeView];

2.设置AVAudioSession

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *error = nil;

if (audioSession.otherAudioPlaying) {

//有其他音乐在后台进行播放时,显示系统控件

[audioSession setActive:NO error:&error];

} else {

//自己的应用会走这一步

[audioSession setActive:YES error:&error];

}

3.监听音量的改变

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(volumeChanged:)

name:@"AVSystemController_SystemVolumeDidChangeNotification"

object:nil];

4.根据音量改变,自定义音量显示UI

- (void)volumeChanged:(NSNotification *)notification

{

float volume =

[[[notification userInfo]

objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]

floatValue];

NSLog(@"当前的音量 = %f", volume);

}

最后

以上就是娇气烧鹅最近收集整理的关于android音量控件苹果主题,iOS自定义音量显示控件的全部内容,更多相关android音量控件苹果主题内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部