我正在使用以下代码播放音频文件。
-(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 播放时如何静音
提前致谢