I've got some .MP4 video files that must be read in a VideoView in an Android activity. These videos include several audio tracks, with each one corresponding to a user language (eg. : English, French, Japanese...).
I've got unexpected trouble finding any help or documentation to provide such a feature. I'm currently able to load the video and play it in a VideoView with a MediaController, but not to change audio tracks.
I'm not sure the Android SDK provides any easy way to do this, which leaves me quite clueless on how to solve my problem. I was thinking of extracting every audio track, loading the audio that I want into a MediaPlayer depending on the language, then make audio and video play together. But I fear that some sync issues could arise and prevent me from doing this.
If you have any clue, any advice to help me getting started with this problem, you're more than welcome.
i) First, you can select a single app from the list to allow you to play sound in the background while another app is already playing audio. ii) Another option is, you can select “All apps” to turn on multi-stream audio. 4] Select your apps and you're good to go.
No 3rd party library required:
mVideoView.setVideoURI(Uri.parse("")); // set video source mVideoView.setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { MediaPlayer.TrackInfo[] trackInfoArray = mp.getTrackInfo(); for (int i = 0; i < trackInfoArray.length; i++) { // you can switch out the language comparison logic to whatever works for you if (trackInfoArray[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO && trackInfoArray[i].getLanguage().equals(Locale.getDefault().getISO3Language()) { mp.selectTrack(i); break; } } return true; } });
As far as I can tell - audio tracks should be encoded in the 3-letter ISO 639-2 in order to be recognized correctly.
Haven't tested myself yet, but it seems that Vitamio library has support for multiple audio tracks (among other interesting features). It is API-compatible with VideoView
class from Android.
Probably you would have to use Vitamio VideoView.setAudioTrack()
to set audio track (for example based on locale). See Vitamio API docs for details.
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