ios - 如何在 iOS 中设置 AVPlayer 声级计?

标签 ios objective-c iphone

我在使用 HTTP 直播的应用程序中使用 AVPlayer。现在我想为该音频流实现一个电平表。 我找到了几个使用 AVAudioPlayer 的例子。但是我找不到解决方案来关闭所需的信息。

AVPlayer.NSURL *url = [NSURL URLWithString:@"http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3"];
self.playerItem = [AVPlayerItem playerItemWithURL:url];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
self.player = [AVPlayer playerWithURL:url];
[self.player play];

最佳答案

请试试这个

if ([mPlayer respondsToSelector:@selector(setVolume:)]) {
    mPlayer.volume = 0.0;
 } else {
     NSArray *audioTracks = mPlayerItem.asset.tracks;

     // Mute all the audio tracks
     NSMutableArray *allAudioParams = [NSMutableArray array];
     for (AVAssetTrack *track in audioTracks) {
         AVMutableAudioMixInputParameters *audioInputParams =[AVMutableAudioMixInputParameters audioMixInputParameters];
         [audioInputParams setVolume:0.0 atTime:kCMTimeZero];
         [audioInputParams setTrackID:[track trackID]];
         [allAudioParams addObject:audioInputParams];
     }
     AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix];
     [audioZeroMix setInputParameters:allAudioParams];

     [mPlayerItem setAudioMix:audioZeroMix]; // Mute the player item
 }

关于ios - 如何在 iOS 中设置 AVPlayer 声级计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38716860/

相关文章:

ios - UIActionSheet 取消按钮的奇怪行为

ios - 在后台触摸时关闭 UIActivityIndi​​catorView

iphone - UIImageJPEGRepresentation 在视网膜显示屏上提供 2x 图像

iphone - 如何在 ios 的模态视图中使导航栏变黑

iphone - 可以更改个人 Apple 开发者帐户的发布者/版权名称吗?

ios - 在 Xcode 调试中观察变量或检查对象的技巧

iphone - 无法将旧的 iOS "iOS 4.0 - 4.1 Device Debugging Support"安装到 Xcode 4.2

ios - 使用内部框架本地化 iOS 应用程序

ios - 如何获取JSON数据中的第一个对象名称?

iphone - 延迟后不使用 NSThread 或 sleep() 执行方法 - 还有其他选择吗?