2011-03-08 94 views
4

我有AVPlayer问题。AVPlayer问题,而直播流媒体(iOS)

1.如何控制音量?

2.如何知道AVPlayer是否因为连接不良而重新加载音乐,我是否有这方面的知识?

+0

你能告诉我你是如何使用AVPlayer播放音乐? – DShah 2011-09-21 16:44:31

+0

在服务器上使用Apple http实时流媒体指南。 – Shay 2011-09-25 18:05:28

回答

7

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

对于音频衰落,您可以使用AVAudioMix。下面是一些代码:

[volumeMixInput setVolume:.5 atTime:CMTimeMakeWithSeconds(15, 1)]; 

希望这有助于:

//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]; 

你也可以用突然设置的混合音量保持在给定的时间。这个API绝对不明显。我强烈推荐观看名为的WWDC 10视频发现AV基金会。非常好。

+1

刚刚意识到这只能回答您的数量问题。可能最好单独发布。 – 2011-06-24 20:59:25

+0

请注意,根据Apple,此方法仅适用于基于_file_的资产。 https://developer.apple.com/library/content/qa/qa1716/_index.html – 2017-12-14 23:33:18