bilibili / ijkplayer

Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.
GNU General Public License v2.0
32.48k stars 8.12k forks source link

IJKAVMoviePlayerController loadedTimeRanges Code Explanation #2495

Open sou1x0 opened 7 years ago

sou1x0 commented 7 years ago

IJKAVMoviePlayerController.m Line790

[timeRangeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

                aTimeRange = [[timeRangeArray objectAtIndex:0] CMTimeRangeValue];

                if(CMTimeRangeContainsTime(aTimeRange, currentTime)) {

                    *stop = YES;

                    foundRange = YES;

                }

            }];

I don't know what's the aTimeRange = [[timeRangeArray objectAtIndex:0] CMTimeRangeValue];'means?

xinzhengzhang commented 7 years ago

That was using to calculate playable duration. Although AVPlayerItem provide a collection of time ranges for which the player has readily available, but as ijkmediaplayback all I need is the first range. Have to say that this way of writing is somewhat ambiguous...

sou1x0 commented 7 years ago

If the timeRangeArray's count is larger than 1, the block will run for multiple times, but actually each time the block is doing the same thing, which always acquires the first element of the array and compare it. Right?

So, why not replace the code with the following:

            if (timeRangeArray.count) {
                aTimeRange = [[timeRangeArray objectAtIndex:0] CMTimeRangeValue];
                if(CMTimeRangeContainsTime(aTimeRange, currentTime)) {
                    foundRange = YES;
                }
            }

What do you think of it?

xinzhengzhang commented 7 years ago

PR is welcome