iOS:访问设备硬件音量控制

iOS: Accessing device hardware audio volume control(iOS:访问设备硬件音量控制)

本文介绍了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 设备上的硬件信息

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"

信息:这只能在真实设备上的模拟器中运行.

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.

this code is using ARC.

此代码也可以使用:

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

这将适用于更新音量,但我不知道这是否是最好的方法

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:访问设备硬件音量控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iOS:访问设备硬件音量控制

基础教程推荐