Umer Khan
Umer Khan

Reputation: 496

How to play Multi Track video file through android MediaPlayer?

I'm working an an App that plays Video files. I'm using android MediaPlayer class to play Video files.

Problem: I want to play let say a video file with multiple embedded Audio Tracks. And then want to allow users choose between the tracks at runtime through an interface.

Is it even possible with Android MediaPlayer? I've seen many application that has this feature like MX PLayer, VLC for android ...

Upvotes: 2

Views: 1258

Answers (1)

kiran Biradar
kiran Biradar

Reputation: 12742

Yes Android MediaPlayer supports playback for multiple embedded Audio Tracks.

You can use selectTrack API to achieve the same.

Syntax goes as below.

public void selectTrack (int index)

index int: the index of the track to be selected. The valid range of the index is 0..total number of track - 1. The total number of tracks as well as the type of each individual track can be found by calling getTrackInfo() method.

Example usage:

     MediaPlayer mplayer = new MediaPlayer();

     MediaPlayer.TrackInfo[] trackInfo = mplayer.getTrackInfo();

        for (int i = 0; i < trackInfoArray.length; i++) {
            if (trackInfo[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_AUDIO) {
                mplayer.selectTrack(i);
                break;
            }

Upvotes: 2

Related Questions