0

I work on iOS and i want to read videos files, one after another, without delay between videos.

Also, i must to be able to refresh the playlist while playing (add videos to the queue).

I've tried with AvQueuePlayer, it works fine, i can refresh the playlist, but there is a little delays between each video.

I've tried with AVMutableComposition, there is no delay between video, but i can't refresh the playlist while playing videos.

Exist it any others solutions? with no delays between video, and where i could refresh the playlist?

Thanks.

EDIT :

The code below works, i play some videos files of 0.5 seconds and there is no gap ! But there is an issue, the sound is fine, but the video freezes every time ! Why ?

 AVMutableComposition *myCompo = [[AVMutableComposition alloc] init];


    for (int countName = 0; countName<10; countName++)
    { 

        //Initialize Asset
        NSURL *MyURL = [[NSBundle mainBundle]
                        URLForResource: [NSString stringWithFormat:@"%d", countName] withExtension:@"mp4"];

        AVURLAsset * myAsset = [[AVURLAsset alloc] initWithURL:MyURL options:nil];


         //Track AUDIO
        AVMutableCompositionTrack *compositionAudioTrack = [myCompo addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

        [compositionAudioTrack setPreferredVolume:1.0];

        AVAssetTrack *clipAudioTrack = [[myAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];



        //Track VIDEO
        AVMutableCompositionTrack *compositionVideoTrack = [myCompo addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

        AVAssetTrack *clipVideoTrack = [[myAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];


        //Time lenght
        CMTime durationFile = clipAudioTrack.timeRange.duration;

        CMTime timeCompo = myCompo.duration;



        //Insert TRACK AUDIO
         BOOL result = [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, durationFile) ofTrack:clipAudioTrack atTime:timeCompo error:nil];


        if(result)
        {
            NSLog(@"Audio Ok");
        }
        else
        {
            NSLog(@"Audio not ok");
        }


         //Insert TRACK VIDEO           
        result =[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, durationFile) ofTrack:clipVideoTrack atTime:timeCompo error:nil];

        if(result)
        {
            NSLog(@"Video Ok");
        }
        else
        {
            NSLog(@"Video not ok");
        }
    }


    dispatch_sync(dispatch_get_main_queue(), ^{

    player2 = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:myCompo]];

    playerLayer2 = [AVPlayerLayer playerLayerWithPlayer:player2];
    playerLayer2.frame = [self view].layer.bounds;
    playerLayer2.videoGravity = AVLayerVideoGravityResizeAspectFill;

    [[self view].layer insertSublayer:playerLayer2 atIndex:0];

    });

    [player2 play];
Julie Bsd
  • 191
  • 1
  • 2
  • 10

2 Answers2

1
  1. AVMutableComposition have property tracks(NSArray), that will be all your videos
  2. use preferedTrackID: to mark the position of the track
  3. - (void)removeTrack:(AVCompositionTrack *)track;to remove any track that you don't need any more
  4. use - (AVMutableCompositionTrack *)addMutableTrackWithMediaType:(NSString *)mediaType preferredTrackID:(CMPersistentTrackID)preferredTrackID; to and additional video track.

    All this should be enough for a playlist.

Good luck!

DimaC
  • 426
  • 2
  • 8
-1

you can download adobe media player or adobe media encore and it will worked, it did it for me, if you want more information about it, you can go to creativecloud and see all the product and you will find it from there which is the best one for you.

user3793997
  • 36
  • 1
  • 6