2 garaster garaster 于 2013.04.01 16:40 提问

如何在AVPlayer播放实现静音

用下面的代码播放音频:

 -(IBAction)hearAudioMessage:(id)sender
{
ChatObject * obj = [chatArray objectAtIndex:rowIndexInt];
 NSString *str=[NSString stringWithFormat:@"http://www.myserver.com/files/%@",obj.voiceFileString];
    self.palyer=[[AVPlayer alloc] initWithURL:[NSURL URLWithString:str]];
    [self.palyer play];
}

我想在播放期间能静音。

用了下面的代码,但是木有实现:

NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];

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 *audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:allAudioParams];

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem setAudioMix:audioMix];

不知道应该怎么能实现呢?

2个回答

g989_1314125
g989_1314125   2013.04.01 17:05
已采纳

很简单的,用下面这行代码静音:

[player pause];
asd767077218
asd767077218   2016.09.05 17:26

[player pause]; 这个是暂停 实现的是播放的时候禁音阿。

Csdn user default icon
上传中...
上传图片
插入图片