AVPlayer Questions, while Live Streaming (iOS)

怎甘沉沦 提交于 2019-12-23 13:11:12

问题


I have AVPlayer Questions.

1.How to control the volume of it?

2.How to know if the AVPlayer is reloading music because bad connection, do i have some inidication of it?


回答1:


AVPlayer uses the system volume, so if you need to provide controls for this you can use MPVolumeView which gives you the slider for volume control.

For audio fading, you can use an AVAudioMix. Here's some code:

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

You can also abruptly set the volume for a mix at a given time with:

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

Hope this helps. This API is definitely not obvious. I'd highly recommend watching the WWDC 10 video entitled Discovering AV Foundation. It's excellent.



来源:https://stackoverflow.com/questions/5237070/avplayer-questions-while-live-streaming-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!