androidaudiosurrounddolby

No audio when streaming ac3 with Android MediaPlayer


I've written a very simple application that loops through a list of videos and streams them from a nodejs server.

I'm just doing your basic video streaming set up with the Android MediaPlayer API, and everything works great, except for surround sound.

With Dolby Digital (ac3), I don't get any audio at all. I tried aac 5.1 and got audio, but it was downconverter to stereo.

public void setupVideoView(Uri videoAddress) {
    emVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            // Prepared Listener
        }
    });
    emVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            // Error Listener
        }
    });
    emVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            setupVideoView(Uri.parse(video_url));
        }
    });
    emVideoView.setVideoURI(videoAddress);
}

I've searched for hours and haven't been able to find a solution. I would expect that Android, if the audio codec isn't supported, would simply pass it through so that something else down the chain could decode it. Maybe I don't fully understand how it works? Any help is greatly appreciated.


Solution

  • If the audio codec isn't available on the device then there's no way for Android MediaPlayer to decode it. LibVLC can convert audio to LPCM. Also, I believe ExoPlayer supports recoding audio but requires a lot more effort.