iOS:访问设备硬件音频音量控制 [英] iOS: Accessing device hardware audio volume control

查看:110
本文介绍了iOS:访问设备硬件音频音量控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在我的内部实施此流光( https://github.com/DigitalDJ/AudioStreamer )应用程序和它运行神奇,但它没有实现音量控制,任何人都有提示如何开始使用卷幻灯片或什么?

I have implemented this streamer(https://github.com/DigitalDJ/AudioStreamer) inside my app and it runs fantastic, however it doesn't have volume controls implemented, anyone have tips how to get started with volume slide or something?

我在寻找一些类似的问题:

I was looking trough some similar questions :

在iOs设备上访问硬件信息

iOS系统音量控制

没有找到任何有用的回答我的问题,如何改变音量(向上/向下),当然钩到某种

Didn't find any of these useful to answer to my question, how to change volume(up/down) and of course hook it to some kind of control i.e. slider, any help is appreciated

推荐答案

确保您将MediaPlayer框架添加到项目中

make sure you add the MediaPlayer framework to your project

您必须在.h文件中定义一个视图,将滑块放在这种情况下viewVolume

you have to define a view in your .h file to put the slider in in this case "viewVolume"

信息:THEN WONT在实际设备上只在模拟器中工作。

INFO: THIS WONT WORK IN A SIMULATOR ONLY ON A REAL DEVICE.

#import <MediaPlayer/MediaPlayer.h>

- (void)showTheVolumeSlider {

    MPVolumeView *volumeViewSlider = [[MPVolumeView alloc] initWithFrame:viewVolume.bounds] ;
    [viewVolume addSubview:volumeViewSlider];
    [volumeViewSlider sizeToFit];

}

此代码使用ARC。

此代码wil也可以工作:

this code wil also work:

musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
    musicPlayer.volume = slider.value;

但是如果你想使用这个,你必须更新滑块的系统,该设备从其他地方调整

but if you want to use this you have to make an system that updates the slider as the volume of the device is adjusted from an other place

这个wil工作更新音量,但我不知道是否是最好的方式

this wil work for updating the volume but i don't know if it's the best way

  timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateSound) userInfo:nil repeats:YES];

此更新UISlider:

this to update the UISlider:

- (void)updateSound {

    musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
    slider.value = musicPlayer.volume;
    // value from 0.0 to 1.0

}

这篇关于iOS:访问设备硬件音频音量控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆