我有一个应用程序,我通过AVPlayer中的URL来流式传输:
NSURL *myURL = [NSURL URLWithString:urlString];
AVPlayer *player = [[AVPlayer alloc]initWithURL:myURL];
self.player = player;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.player currentItem]];
[self.player addObserver:self forKeyPath:@"status" options:0 context:nil];
[self.player play];
我想要的是有一个滑块来控制音量。我知道使用AVAudioPlayer很容易,因为它有一个属性,但不是AVPlayer。
我怎么能这样做?我是否必须使用AVAsset,因为我看到there,以及如何(因为我现在不在我的代码中使用它们)?
谢谢你!
答案 0 :(得分:0)
您必须使用UISlider valueChanged:action中指定的卷创建AVMutableAudioMix。像这样:
- (IBAction) sliderValueChanged:(UISlider *)sender {
AVMutableAudioMixInputParameters *audioInputParams =
[AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:sender.value atTime:kCMTimeZero];
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:@[audioInputParams]];
[[player currentItem] setAudioMix:audioMix]; (from a UISlider valueChanged action)
}