Lor*_*öhr 7 iphone volume avaudioplayer avplayer
我想创建一个按钮来静音来自AVPlayer的音频.
为什么我不能将.volume与AVPlayer一起使用,只能使用AVAudioPlayer?还有另一种改变音量的方法吗?
例如 music.volume = 0.0;
谢谢你的回答.
Dou*_*oug 13
从iOS 7开始,只需致电:
myAvPlayer.volume = 0;
Run Code Online (Sandbox Code Playgroud)
否则,你将不得不使用恼人的setAudioMix解决方案.我在我的应用程序中检测到对此的支持,如下所示:
if ([mPlayer respondsToSelector:@selector(setVolume:)]) {
mPlayer.volume = 0.0;
} else {
NSArray *audioTracks = mPlayerItem.asset.tracks;
// Mute all the audio tracks
NSMutableArray *allAudioParams = [NSMutableArray array];
for (AVAssetTrack *track in audioTracks) {
AVMutableAudioMixInputParameters *audioInputParams =[AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:0.0 atTime:kCMTimeZero];
[audioInputParams setTrackID:[track trackID]];
[allAudioParams addObject:audioInputParams];
}
AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix];
[audioZeroMix setInputParameters:allAudioParams];
[mPlayerItem setAudioMix:audioZeroMix]; // Mute the player item
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12803 次 |
| 最近记录: |