Question

I'm playing a video file from the documents directory, but I can't change the volume. Actually I can play a file from the music video library and change the volume, but not for the precharged ( from iTunes with File Sharing ) videos! What can I do?

That's the slider that is used like a crossfader between the videos for manage the volume:

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];
Était-ce utile?

La solution

I found the solution.

When I load the track in the avplayeritem, that is divided in an "array" of audio, video, timecode ( if present ). In case of video loaded from iTunes, the file had video, sound, timecode and I must load the sound part in the audiomix. Before I discover that I load the avplayeritem[0] but it's wrong because in the file loaded from document library the sound part is in another position. That's the solution:

//load the sound part in an array
audioTrackssx = [videoSinistra tracksWithMediaType:AVMediaTypeAudio];


//the sound part must be only one
[audioInputParams setTrackID:[audioTrackssx[0] trackID]];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top