Example usage for android.widget VideoView setKeepScreenOn

List of usage examples for android.widget VideoView setKeepScreenOn

Introduction

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

Prototype

public void setKeepScreenOn(boolean keepScreenOn) 

Source Link

Document

Controls whether the screen should remain on, modifying the value of #KEEP_SCREEN_ON .

Usage

From source file:Main.java

/**
 * Play video file from res folder.//from   w  w  w .ja v a2 s  .  c  om
 * 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;
}