Search code examples
androidvitamio

How to use the Vitamio VideoView multiple times?


I am using the Vitamio library, and need to play a short video every minute. Some time it works just fine, but after a few executions Vitamio begins to show a blank screen instead of playing video. Native VideoView works great in such a situation, but I need to support more video formats.

Here's the Vitamio log when video is showing:

09-12 15:30:35.683  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER INIT BEGIN
09-12 15:30:35.683  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER INIT END
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:30:35.693  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ PREPARE SIG: 0
09-12 15:30:35.693  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE START
09-12 15:30:35.693  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE ATTACHED
09-12 15:30:35.703  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:30:35.703  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ OPEN FILE /mnt/sdcard/Android/Data/com.test.simdisplay/adv/FILE.mp4
09-12 15:30:35.803  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ META AUDIO: , META SUBTITLE:
09-12 15:30:35.803  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:30:35.803  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:30:35.803  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ WOW: BRILLIANT C COUNT 4
09-12 15:30:35.813  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ OPEN STREAM VIDEO BEGIN
09-12 15:30:35.813  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ OPEN STREAM VIDEO END
09-12 15:30:35.813  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ DEMUX SIG: 0
09-12 15:30:35.813  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE DETTACHED, ret = 0
09-12 15:30:35.813  26713-26747/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE END
09-12 15:30:35.813  26713-26752/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CC: ARMYUV420 0
09-12 15:30:35.813  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ start
09-12 15:30:35.813  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ stop
09-12 15:30:35.873  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ start
09-12 15:30:35.953  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ start
09-12 15:30:42.343  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ stop
09-12 15:30:42.373  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ start
09-12 15:30:47.523  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ stop
09-12 15:30:47.543  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ start
09-12 15:30:50.613  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ stop
09-12 15:30:50.613  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER RELEASE BEGIN
09-12 15:30:50.613  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ prepare pthread_cancel / pthread_kill 3
09-12 15:30:50.613  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ prepare pthread_join 0
09-12 15:30:50.613  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ demux pthread_kill 0
09-12 15:30:50.623  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ demux pthread_join 0
09-12 15:30:50.623  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FILE CLOSE BEGIN
09-12 15:30:50.623  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE STREAM VIDEO BEGIN
09-12 15:30:50.623  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE STREAM VIDEO END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE AVFORMAT BEGIN
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE AVFORMAT END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE VIDEOPIC BEGIN
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE VIDEOPIC 2 END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE SUBPIC BEGIN
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE SUBPIC 1 END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE AUDIOFRAME BEGIN
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE AUDIOFRAME 8 END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ DELETE GLOBAL REF BEGIN
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ DELETE GLOBAL REF END
09-12 15:30:50.633  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FILE CLOSE END
09-12 15:30:50.713  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER RELEASE END
09-12 15:30:50.763  26713-26715/com.test.testhtmlbuttons D/dalvikvm﹕ GC_CONCURRENT freed 435K, 10% free 4313K/4776K, paused 3ms+2ms, total 18ms
09-12 15:30:50.763  26713-26722/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ NATIVE FINALIZE VPLAYER
09-12 15:30:50.763  26713-26722/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ NATIVE FINALIZE VPLAYER END

And that when it’s not:

09-12 15:36:50.313  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER INIT BEGIN
09-12 15:36:50.313  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:36:50.313  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER INIT END
09-12 15:36:50.313  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:36:50.313  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:36:50.323  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:36:50.323  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Application package name: com.test.testhtmlbuttons
09-12 15:36:50.323  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ PREPARE SIG: 0
09-12 15:36:50.323  26713-26908/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE START
09-12 15:36:50.323  26713-26908/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE ATTACHED
09-12 15:36:50.323  26713-26908/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ Copyright (c) YIXIA (http://yixia.com).
    THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
09-12 15:36:50.323  26713-26908/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ OPEN FILE /mnt/sdcard/Android/Data/com.test.simdisplay/adv/FILE.mp4
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ prepare pthread_cancel / pthread_kill 0
09-12 15:36:50.333  26713-26908/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ THREAD PREPARE DETTACHED, ret = 0
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ prepare pthread_join 0
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FILE CLOSE BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE AVFORMAT BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ CLOSE AVFORMAT END
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE VIDEOPIC BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE VIDEOPIC 2 END
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE SUBPIC BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE SUBPIC 1 END
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE AUDIOFRAME BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FREE AUDIOFRAME 8 END
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ DELETE GLOBAL REF BEGIN
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ DELETE GLOBAL REF END
09-12 15:36:50.333  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ FILE CLOSE END
09-12 15:36:50.343  26713-26715/com.test.testhtmlbuttons D/dalvikvm﹕ GC_CONCURRENT freed 387K, 11% free 4316K/4840K, paused 3ms+2ms, total 22ms
09-12 15:36:50.413  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER RELEASE BEGIN
09-12 15:36:50.413  26713-26713/com.test.testhtmlbuttons I/Vitamio[4.2.6][Player]﹕ VPLAYER RELEASE END

Here’s my code snippet to start video:

if(mVideoView.isPlaying()) {
    mVideoView.stopPlayback();
    mVideoView.destroyDrawingCache();
}
mVideoView.setVisibility(View.VISIBLE);
mVideoView.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mVideoView.setMediaController(null);
mVideoView.requestFocus();
mVideoView.start();

Has anyone faced such a problem? How do I properly release all Vitamio resources and reuse VideoView? This changes nothing:

mVideoView = null;
mVideoView = (VideoView) findViewById(R.id.videoViewForAdv);    

Solution

  • I found a solution to my problem. I just changed Vitamio VideoView to Vitamio MediaPlayer. Now all working fine. Here is my result code to play video:

    releaseMediaPlayer();
    try {
        mMediaPlayer = new MediaPlayer(getApplicationContext());
        mMediaPlayer.setDataSource(path); //Path to video file
        mMediaPlayer.setDisplay(holder); //Set SurfaceHolder
        mMediaPlayer.prepare();
        mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
           @Override
           public void onPrepared(MediaPlayer mp) {
                 startVideoPlayback();
           }
        });
    }
    catch (Exception e){} 
    
    ...
    
    private void releaseMediaPlayer() {
        if (mMediaPlayer != null) {
            if(mMediaPlayer.isPlaying())
                mMediaPlayer.stop();
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }
    
    private void startVideoPlayback() {
        holder.setSizeFromLayout();
        mMediaPlayer.start();
    }