AVPlayer问题,而直播(iOS) [英] AVPlayer Questions, while Live Streaming (iOS)

查看:218
本文介绍了AVPlayer问题,而直播(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AVPlayer问题。

I have AVPlayer Questions.

1.如何控制音量?

2。如何知道AVPlayer是否因为连接错误而重新加载音乐,我是否有一些消息?

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

推荐答案

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

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.

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

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

希望这会有所帮助。这个API绝对不明显。我强烈建议您观看名为发现AV基础的WWDC 10视频。这很棒。

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.

这篇关于AVPlayer问题,而直播(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆