我正在播放文档目录中的视频文件,但我无法更改音量。 实际上我可以播放音乐视频库中的文件并更改音量,但不能用于预充电(来自iTunes with File Sharing)视频! 我该怎么办?
这是用于管理音量的视频之间的交叉渐变器的滑块:
AVMutableAudioMixInputParameters* audioInputParams2 = [AVMutableAudioMixInputParameters audioMixInputParameters];
CMTime currentTime = [videoItemDestra currentTime];
//se il video non c'è setta il tempo a zero, almeno non crasha
if(CMTIME_IS_INVALID(currentTime)){
currentTime = kCMTimeZero;
}
//se il pulsante muto è attivo non cambiare volume
if( mutedx ==1){
[audioInputParams2 setVolume:0 atTime:currentTime];
}else{
[audioInputParams2 setVolume:(_volumeSliderAvplayer2.value/100) atTime:currentTime];
}
[audioInputParams2 setTrackID:[videoDestra.tracks[0] trackID]];
NSMutableArray * allAudioParams2= [[NSMutableArray alloc]initWithObjects:audioInputParams2, nil];
AVMutableAudioMix * audioMix2 = [AVMutableAudioMix audioMix];
[audioMix2 setInputParameters:allAudioParams2];
AVMutableAudioMixInputParameters* audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
CMTime currentTime2 = [videoItemSinistra currentTime];
//se il video non c'è setta il tempo a zero, almeno non crasha
if(CMTIME_IS_INVALID(currentTime2)){
currentTime2 = kCMTimeZero;
}
//se il pulsante muto è attivo non cambiare volume
if( mutesx ==1){
[audioInputParams setVolume:0 atTime:currentTime2];
}else{
[audioInputParams setVolume:(1-(_volumeSliderAvplayer2.value/100)) atTime:currentTime2];
}
[audioInputParams setTrackID:[videoSinistra.tracks[0] trackID]];
NSMutableArray *allAudioParams= [[NSMutableArray alloc]initWithObjects:audioInputParams, nil];
AVMutableAudioMix* audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:allAudioParams];
[videoItemSinistra setAudioMix:audioMix];
[videoItemDestra setAudioMix:audioMix2];
答案 0 :(得分:0)
我找到了解决方案。
当我在avplayeritem中加载轨道时,它被划分为音频,视频,时间码(如果存在)的“阵列”。 如果从iTunes加载视频,该文件有视频,声音,时间码,我必须加载audiomix中的声音部分。 在我发现加载avplayeritem [0]之前,这是错误的,因为在从文档库加载的文件中,声音部分处于另一个位置。 这是解决方案:
//load the sound part in an array
audioTrackssx = [videoSinistra tracksWithMediaType:AVMediaTypeAudio];
//the sound part must be only one
[audioInputParams setTrackID:[audioTrackssx[0] trackID]];