問題描述
我已經在里面實現了這個流媒體(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:訪問設備硬件音量控制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!