AVPlayer issues while Live Streaming (iOS)

I have AVPlayer questions.

1.How to control its volume?

2. How do I know if AVPlayer is reloading music due to a bad connection, do I have any suspicion?

+4
source share
1 answer

AVPlayeruses the system volume, so if you need to provide controls for this, you can use MPVolumeViewthat gives you a slider for adjusting the volume.

You can use to fade out the sound AVAudioMix. Here is the 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 sharply set the volume for the mix at a given time with:

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

, . API . WWDC 10 " AV Foundation". .

+7

All Articles