我正在使用以下代码播放音频文件。
-(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];
请建议任何其他选择?或者我们如何在使用AVPlayer进行播放时将音频静音
提前致谢
答案 0 :(得分:-2)
使用以下行将音频静音
[玩家暂停];