用下面的代碼播放音頻:
-(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];
不知道應該怎麼能實現呢?
很簡單的,用下面這行代碼靜音:
[player pause];