更改AVPlayer卷

时间:2014-06-09 19:58:27

标签: ios objective-c uiwebview avplayer mpvolumeview

所以我使用AVPlayer播放带有音频的视频文件,并在视频上覆盖了一个UIWebView,该视频具有播放/暂停,搜索等控制权。我也有一个我想要实现的音量滑块,但到目前为止我没有运气。这是我的代码改变音量:

- (void)setPlayerVolume:(float)volume
{
    NSArray *tracks = [self.player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio];
    NSMutableArray *audio = [NSMutableArray array];

    for (AVAssetTrack *track in tracks) {
        AVMutableAudioMixInputParameters *input = [AVMutableAudioMixInputParameters audioMixInputParameters];
        [input setVolume:volume atTime:kCMTimeZero];
        [input setTrackID:track.trackID];
        [audio addObject:input];
    }

    AVMutableAudioMix *mix = [AVMutableAudioMix audioMix];
    [mix setInputParameters:audio];
    [self.player.currentItem setAudioMix:mix];
}

我一直在阅读,这似乎是使用 MPVolumeView 的唯一解决方案。还有其他解决方案吗?

感谢您的帮助,非常感谢。

0 个答案:

没有答案