I can assign subtitle once but after that if I tried to change subtitle. It won't accept new one, it display previous one every-time.
Below code I'm using to change subtitle.
MediaPlayer mediaPlayer;
public void changeSubtitle()
{
//disable subtitle if it has
if(textTrackIndex!=0){
mediaPlayer.deselectTrack(textTrackIndex);
textTrackIndex=0;
mediaPlayer.setOnTimedTextListener(null);
}
//try to asssign new subtitle
mediaPlayer
.addTimedTextSource(
(Environment.getExternalStorageDirectory()
.getPath()
+ "/"+"filename",
MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP);
int textTrackIndex = findTrackIndexFor(TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT,mediaPlayer.getTrackInfo());
if (textTrackIndex >= 0) {
mediaPlayer.selectTrack(textTrackIndex);
} else {
Log.w(TAG, "Cannot find text track!");
}
mediaPlayer.setOnTimedTextListener(this);
}
private int findTrackIndexFor(int mediaTrackType, TrackInfo[] trackInfo)
{
int index = -1;
for (int i = 0; i < trackInfo.length; i++) {
if (trackInfo[i].getTrackType() == mediaTrackType) {
return i;
}
}
return index;
}
MPC Options -> Subtitles -> Default Style. There you can choose the font, colors, and font size.
Go to Tools → Preferences (set Show Settings to All) and Video → Subtitles/OSD → Text renderer and adjust anything you want.
Have a look at the state diagram. Try to reset()
and release()
your mediaPlayer
before you initialize it again with newly associated resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With