Iphone 直播时的AVPlayer问题(iOS)
我有一些问题 1.如何控制它的音量Iphone 直播时的AVPlayer问题(iOS),iphone,ios,ios4,volume,avplayer,Iphone,Ios,Ios4,Volume,Avplayer,我有一些问题 1.如何控制它的音量 2.如何知道AVPlayer是否因为连接不良而重新加载音乐,我是否有一些指示?AVPlayer使用系统音量,因此,如果需要为此提供控制,可以使用MPVolumeView提供音量控制滑块 对于音频衰减,您可以使用AVAudioMix。下面是一些代码: //given an AVAsset called asset... AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset]; id
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绝对不明显。我强烈推荐观看题为“发现AV基金会”的WWDC 10视频。太棒了。刚刚意识到这只回答了你的音量问题。最好单独发布。注意,对于每个苹果来说,这种方法只适用于基于文件的资产。你能告诉我你是如何在服务器上使用苹果http直播指南使用AVPlayer播放音乐的吗。