Only select timed metadata tracks

This commit is contained in:
Hampton Maxwell 2018-12-13 12:43:11 -08:00 committed by GitHub
parent 0a12f7389e
commit 46701448e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -571,11 +571,7 @@ public class ReactVideoView extends ScalableVideoView implements
});
}
// Select track (so we can use it to listen to timed meta data updates)
try{
mp.selectTrack(0);
}catch (Throwable t){
}
selectTimedMetadataTrack(mp);
}
@Override
@ -610,12 +606,7 @@ public class ReactVideoView extends ScalableVideoView implements
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// Select track (so we can use it to listen to timed meta data updates)
try{
mp.selectTrack(0);
}catch (Throwable t){
}
selectTimedMetadataTrack(mp);
mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
}
@ -768,4 +759,20 @@ public class ReactVideoView extends ScalableVideoView implements
return result;
}
// Select track (so we can use it to listen to timed meta data updates)
private void selectTimedMetadataTrack(MediaPlayer mp) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return;
}
try {
MediaPlayer.TrackInfo[] trackInfo = mp.getTrackInfo();
for (int i = 0; i < trackInfo.length; ++i) {
if (trackInfo[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
mp.selectTrack(i);
break;
}
}
} catch (Exception e) {}
}
}