如何静音视频播放在AVPlayer?

时间:2021-02-25 18:57:54

Im playing a video in AVPlayer, and now I need to mute the audio alone while playing it. Please suggest how to do in objective C.

我在AVPlayer上播放一个视频,现在我需要在播放视频的时候把音频关掉。请建议如何在objective C中做。

Thanks, Suresh

谢谢,苏雷什

3 个解决方案

#1


21  

Since iOS7 you can set the AVPlayer isMuted property to true.

由于iOS7,您可以将AVPlayer ismute属性设置为true。

In Objective C the property is called muted.

在Objective - C中,属性被称为。

Reference: https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted

参考:https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted

#2


9  

This should see you through...

这将使你度过……

AVURLAsset *asset = [[avPlayer currentItem] asset];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];

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

[[avPlayer currentItem] setAudioMix:audioZeroMix];

#3


3  

SWIFT 2.0 and SWIFT 3.0 (As of July 5, 2017)

SWIFT 2.0和SWIFT 3.0(截止2017年7月5日)

For those of you curious about Swift it is simply just:

对于那些好奇斯威夫特的人来说,这只是:

self.avPlayer.muted = true

EASIEST way for OBJECTIVE-C:

objective - c的简单的方法:

self.avPlayer.muted = true;

#1


21  

Since iOS7 you can set the AVPlayer isMuted property to true.

由于iOS7,您可以将AVPlayer ismute属性设置为true。

In Objective C the property is called muted.

在Objective - C中,属性被称为。

Reference: https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted

参考:https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted

#2


9  

This should see you through...

这将使你度过……

AVURLAsset *asset = [[avPlayer currentItem] asset];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];

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

[[avPlayer currentItem] setAudioMix:audioZeroMix];

#3


3  

SWIFT 2.0 and SWIFT 3.0 (As of July 5, 2017)

SWIFT 2.0和SWIFT 3.0(截止2017年7月5日)

For those of you curious about Swift it is simply just:

对于那些好奇斯威夫特的人来说,这只是:

self.avPlayer.muted = true

EASIEST way for OBJECTIVE-C:

objective - c的简单的方法:

self.avPlayer.muted = true;