Skip to content

Commit

Permalink
refactor(appleavplayer): fix runtime error nan
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Sep 2, 2020
1 parent 971d28b commit 37e45a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mediaPlayer/externalPlayer/AppleAVPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,19 @@
return 0;
}
AVPlayer *player = (__bridge AVPlayer *)this->avPlayer;
if (isnan(CMTimeGetSeconds(player.currentItem.duration))) {
return 0;
}
return (int64_t)(CMTimeGetSeconds(player.currentItem.duration) * 1000);
}

int64_t AppleAVPlayer::GetPlayingPosition()
{
AVPlayer *player = (__bridge AVPlayer *)this->avPlayer;
NSTimeInterval currentTimeSeconds = CMTimeGetSeconds(player.currentTime);
if (isnan(currentTimeSeconds)) {
return 0;
}
return (int64_t)(currentTimeSeconds * 1000);
}

Expand Down
3 changes: 3 additions & 0 deletions mediaPlayer/externalPlayer/AppleAVPlayerUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ + (int64_t)getBufferPosition:(AVPlayerItem *)playerItem {
NSTimeInterval loadStartSeconds = CMTimeGetSeconds(timeRange.start);
NSTimeInterval loadDurationSeconds = CMTimeGetSeconds(timeRange.duration);
NSTimeInterval currentLoadTotalTime = loadStartSeconds + loadDurationSeconds;
if (isnan(currentLoadTotalTime)) {
return 0;
}
int64_t position = (int64_t)(currentLoadTotalTime * 1000);
return position;
}
Expand Down

0 comments on commit 37e45a3

Please sign in to comment.