Example usage for android.widget VideoView setOnCompletionListener

List of usage examples for android.widget VideoView setOnCompletionListener

Introduction

In this page you can find the example usage for android.widget VideoView setOnCompletionListener.

Prototype

public void setOnCompletionListener(OnCompletionListener l) 

Source Link

Document

Register a callback to be invoked when the end of a media file has been reached during playback.

Usage

From source file:Main.java

/**
 * Play video file from res folder./*  w ww  . ja  v a 2  s  .c o m*/
 * Then call video.start();
 * @param activity - current Activity
 * @param videoViewId R.id.introVideo
 * @param videoResourceId R.raw.intro - res/raw/intro.mp4
 * @return VideoView
 */
public static VideoView playVideo(Activity activity, int videoViewId, int videoResourceId,
        MediaPlayer.OnCompletionListener listener) {
    activity.getWindow().setFormat(PixelFormat.TRANSLUCENT);
    VideoView view = (VideoView) activity.findViewById(videoViewId);
    view.setVideoURI(
            Uri.parse("android.resource://" + activity.getPackageName() + File.separator + videoResourceId));
    view.setKeepScreenOn(true);
    view.setMediaController(null);
    view.setOnCompletionListener(listener);
    view.requestFocus();
    return view;
}

From source file:com.javierarboleda.visualtilestogether.activities.SignInActivity.java

private void initTutorialView() {
    mPager = (ViewPager) findViewById(R.id.tutorial_view_pager);
    mPager.setAdapter(new TutorialImageAdapter(this));
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tutorial_tab_layout);
    tabLayout.setupWithViewPager(mPager, true);

    mTimer = new Timer();
    mTimer.scheduleAtFixedRate(new RemindTask(), 0, 4000);

    mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override/*from   w ww. j a v a  2s .  c  om*/
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            mPage = position;
        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    Animation animation = new AlphaAnimation(0f, 1f);
    animation.setDuration(1400);
    findViewById(R.id.ivTutorial).startAnimation(animation);
    findViewById(R.id.tutorial_view_pager).startAnimation(animation);
    findViewById(R.id.tutorial_tab_layout).startAnimation(animation);
    findViewById(R.id.view_footer).startAnimation(animation);

    final VideoView videoView = (VideoView) findViewById(R.id.vvTutorialVideo);

    videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video_tutorial_1));

    videoView.requestFocus();

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

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            videoView.seekTo(0);
            videoView.start();
        }
    });
}

From source file:im.vector.adapters.VectorMediasViewerAdapter.java

/**
 * Load the video items/*from  ww w  . jav a  2s . c  o  m*/
 * @param view the page view
 * @param thumbnailUrl the thumbnail URL
 * @param videoUrl the video Url
 * @param videoMimeType the video mime type
 */
private void loadVideo(final int position, final View view, final String thumbnailUrl, final String videoUrl,
        final String videoMimeType) {
    final VideoView videoView = (VideoView) view.findViewById(R.id.media_slider_videoview);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);
    final ImageView playView = (ImageView) view.findViewById(R.id.media_slider_video_playView);

    displayVideoThumbnail(view, !videoView.isPlaying());

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
        }
    });

    // the video is renderer in DSA so trap the on click on the video view parent
    ((View) videoView.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            stopPlayingVideo();
            displayVideoThumbnail(view, true);
        }
    });

    // manage video error cases
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
            return false;
        }
    });

    // init the thumbnail views
    mMediasCache.loadBitmap(mSession.getHomeserverConfig(), thumbView, thumbnailUrl, 0, 0, null);

    playView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // init the video view only if there is a valid file
            // check if the media has been downloaded
            File srcFile = mMediasCache.mediaCacheFile(videoUrl, videoMimeType);

            if (null != srcFile) {
                playVideo(view, videoView, videoUrl, videoMimeType);
            } else {
                mAutoPlayItemAt = position;
                downloadVideo(view, position);
            }
        }
    });
}

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

/**
 * Load the video items/*from  w  w w  . ja v a2  s. c o  m*/
 * @param view the page view
 * @param thumbnailUrl the thumbnail URL
 * @param videoUrl the video Url
 * @param videoMimeType the video mime type
 */
private void loadVideo(final int position, final View view, final String thumbnailUrl, final String videoUrl,
        final String videoMimeType) {
    final VideoView videoView = (VideoView) view.findViewById(R.id.media_slider_videoview);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);
    final ImageView playView = (ImageView) view.findViewById(R.id.media_slider_video_playView);

    displayVideoThumbnail(view, !videoView.isPlaying());

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
        }
    });

    // the video is renderer in DSA so trap the on click on the video view parent
    ((View) videoView.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            stopPlayingVideo();
            displayVideoThumbnail(view, true);
        }
    });

    // manage video error cases
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
            return false;
        }
    });

    // init the thumbnail views
    mMediasCache.loadBitmap(mSession.getHomeserverConfig(), thumbView, thumbnailUrl, 0, 0, null, null);

    playView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // init the video view only if there is a valid file
            // check if the media has been downloaded
            File srcFile = mMediasCache.mediaCacheFile(videoUrl, videoMimeType);

            if (null != srcFile) {
                playVideo(view, videoView, videoUrl, videoMimeType);
            } else {
                mAutoPlayItemAt = position;
                downloadVideo(view, position);
            }
        }
    });
}