Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import android.app.Activity;

import android.graphics.PixelFormat;

import android.media.MediaPlayer;

import android.net.Uri;

import android.widget.VideoView;

public class Main {
    /**
     * Play video file from res folder.
     * 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;
    }
}