-1

我正在播放文档目录中的视频文件,但无法更改音量。实际上,我可以播放音乐视频库中的文件并更改音量,但不能播放预充电(来自带有文件共享的 iTunes)的视频!我能做些什么?

这是用于管理音量的视频之间的交叉渐变器的滑块:

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];
4

1 回答 1

0

我找到了解决方案。

当我在 avplayitem 中加载轨道时,它被划分为音频、视频、时间码(如果存在)的“数组”。如果从 iTunes 加载视频,该文件有视频、声音、时间码,我必须在音频混合中加载声音部分。在我发现我加载了 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]];
于 2013-09-06T21:16:51.270 回答