Android : multiple audio tracks in a VideoView?

后端 未结 4 547
旧巷少年郎
旧巷少年郎 2021-02-02 08:52

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 languag

相关标签:
4条回答
  • 2021-02-02 09:37

    Now you can Play Multiple audio files through ExoPlayer.

    Here is the details,

    1. https://exoplayer.dev/track-selection.html[1]
    2. Exo Player Track Selection
    0 讨论(0)
  • 2021-02-02 09:43

    VideoView class can't support your require.U must parse to get audio stream data(you want) to play with AudioTrack class on java layer.

    0 讨论(0)
  • 2021-02-02 09:47

    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.

    0 讨论(0)
  • 2021-02-02 09:53

    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.

    0 讨论(0)
提交回复
热议问题