protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview_main);
MediaPlayer mp=new MediaPlayer();
videoview = (VideoView) findViewById(R.id.VideoView);
}
pDialog = new ProgressDialog(VideoViewActivity.this);
// Set progressbar title
pDialog.setTitle("Android Video Streaming Tutorial");
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
try {
MediaController mediacontroller = new MediaController(
VideoViewActivity.this);
mediacontroller.setAnchorView(videoview);
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
InputStream i = getApplicationContext().getResources().openRawResource(R.raw.test);
videoview.addSubtitleSource(i ,MediaFormat.createSubtitleFormat("text/srt",Locale.ENGLISH.getLanguage()));
videoview.start();
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.requestFocus();
}
}
The above code is showing java.lang.NoSuchMethodError: when i try to run it on android 4.2 version. Is their is any other way so that i can use subtitles in video view in android?
Do not use default Android media player. i use ijkPlayer, there also is Vlc lib, Vitamo and many other media players for android. not sure tho if every one of my mentioned players have subtitle adding feature.