1

I am developing a DASH client for Android and am testing the playback multiple video segments in mp4 format on Android. Therefore I tried two approaches so far:

using VideoView:

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        videoView.setVideoURI(uri);    
        videoView.requestFocus();
        videoView.setVisibility(View.VISIBLE);
        videoView.start();
    }
});

using TextureView:

mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mediaPlayer) {
        mediaPlayer.start();
    }
});

mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        try {
            mMediaPlayer.setSurface(surface);
            mMediaPlayer.reset();
            mMediaPlayer.setDataSource(file.getAbsolutePath());
            mMediaPlayer.prepareAsync();
    } catch (Exception e) {
        e.printStackTrace();
        }    
    }
});

Okay both work but have a little lag when switching to the next file. What can cause that? Am I doing something wrong and can improve the code? I read about using the MediaExtractor and MediaCodec APIs for better playback of multiple videos which were also improved for DASH compatibility with Android verisons 4.3 and 4.4 but I haven't understood yet how to use them to play video and audio on a surface. I can only find sources on how to us them in order to play video or audio.

I hope somebody can help me to play multiple video segments in succession seamlessly.

R1P4
  • 11
  • 1
  • 1
    There's a bit of a startup delay when talking to a codec, for the initial configuration and the latency from input to output. You may need to "warm it up" by starting the player, sending it a few frames, and pausing it, all while the previous video is still showing on screen. Ideally the non-displayed frames are blanks inserted into the start of the stream. Doing this is probably at least as difficult as it sounds. :-| – fadden May 16 '14 at 00:44
  • Hey thanks for your answer! I focused on something else until now because it was so frustrating but now I come back to that problem and want to fix it... Do you think using the MediaCodec API might be a better approach? I can't really wrap my head around how to play multiple files with it with audio + video but if it fits this problem better I have to try I think. The last thing I tried was to always have one mediaplayer prepared that is going to be used next but this also caused some delay. Is there really no easy way around it? – R1P4 Jun 05 '14 at 19:49

0 Answers0