AVPlayer问题,而直播stream媒体(iOS)

我有AVPlayer的问题。

1.如何控制音量?

2.如何知道AVPlayer是否因为连接不良而重新加载音乐,我有一些解决办法吗?

AVPlayer使用系统音量,所以如果您需要为此提供控制,您可以使用MPVolumeView ,它为您提供音量控制的滑块。

对于audio衰落,您可以使用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绝对不明显。 我强烈推荐观看名为“ 发现AV基础 ”的WWDC 10video。 很好。