我有 AVPlayer 问题。
1.如何控制音量?
2.如何知道AVPlayer是否因为连接不良而重新加载音乐,我有一些指示吗?
AVPlayer
使用系统音量,因此如果您需要为此提供控件,您可以使用MPVolumeView
这为您提供了音量控制滑块。
对于音频衰落,您可以使用AVAudioMix
。这是一些代码:
//given an AVAsset called asset...
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
id audioMix = [[AVAudioMix alloc] init];
id volumeMixInput = [[AVMutableAudioMixInputParameters alloc] init];
//fade volume from muted to full over a period of 3 seconds
[volumeMixInput setVolumeRampFromStartVolume:0 toEndVolume:1 timeRange:
CMTimeRangeMake(CMTimeMakeWithSeconds(0, 1), CMTimeMakeWithSeconds(3, 1))];
[volumeMixnput setTrackID:[[asset tracks:objectAtIndex:0] trackID]];
[audioMix setInputParameters:[NSArray arrayWithObject:volumeMixInput]];
[playerItem setAudioMix:audioMix];
您还可以使用以下命令在给定时间突然设置混音的音量:
[volumeMixInput setVolume:.5 atTime:CMTimeMakeWithSeconds(15, 1)];
希望这可以帮助。这个API肯定不明显。我强烈建议您观看 WWDC 10 视频,标题为发现 AV 基金会。太棒了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)