Skip to content

Commit

Permalink
Only select timed metadata tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
cobarx authored Dec 13, 2018
1 parent 0a12f73 commit 4670144
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions android/src/main/java/com/brentvatne/react/ReactVideoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,7 @@ public void run() {
});
}

// Select track (so we can use it to listen to timed meta data updates)
try{
mp.selectTrack(0);
}catch (Throwable t){
}
selectTimedMetadataTrack(mp);
}

@Override
Expand Down Expand Up @@ -610,12 +606,7 @@ public boolean onInfo(MediaPlayer mp, int what, int extra) {

@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);
}

Expand Down Expand Up @@ -768,4 +759,20 @@ public static Map<String, String> toStringMap(@Nullable ReadableMap readableMap)

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) {}
}
}

0 comments on commit 4670144

Please sign in to comment.