<commit_before>package com.shortsands.videoplayer;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.VideoView;
/**
 * Created by garygriswold on 1/26/17.
 * This is based up the following plugin:
 * https://github.com/nchutchind/cordova-plugin-streaming-media
 */
public class VideoActivity extends Activity implements
        MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
        MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener,
        MediaPlayer.OnSeekCompleteListener, MediaPlayer.OnBufferingUpdateListener {
    private final static String TAG = "VideoActivity";
    private VideoPersistence videoPersistence = new VideoPersistence(this);
    private VideoView videoView;
    private MediaController mediaController;
    private MediaPlayer mediaPlayer;
    private ProgressBar progressBar;
    private String videoId;
    private String videoUrl;
    private int currentPosition = 0;
    private boolean videoPlaybackComplete = false;
    
    public String getVideoId() {
	    return(this.videoId);
    }
    public void setVideoId(String id) {
	    this.videoId = id;
    }
    public String getVideoUrl() {
	    return(this.videoUrl);
    }
    public void setVideoUrl(String url) {
	    this.videoUrl = url;
    }
    public int getCurrentPosition() {
	    return((this.videoView != null) ? this.videoView.getCurrentPosition() : 0);
    }
    public void setCurrentPosition(int pos) {
	    this.currentPosition = pos;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate CALLED " + System.currentTimeMillis());

        Window window = this.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setBackgroundColor(Color.BLACK);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

        this.videoView = new VideoView(this);
        this.videoView.setLayoutParams(layoutParams);
        relativeLayout.addView(this.videoView);

        // Create startup progress animation
        this.progressBar = new ProgressBar(this);
        this.progressBar.setIndeterminate(true);
        RelativeLayout.LayoutParams progLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        progLayout.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        this.progressBar.setLayoutParams(progLayout);
        relativeLayout.addView(this.progressBar);
        this.progressBar.bringToFront();

        setContentView(relativeLayout);
        
        this.videoView.setOnPreparedListener(this);
        this.videoView.setOnCompletionListener(this);
        //this.videoView.setOnInfoListener(this); requires SDK 17
        this.videoView.setOnErrorListener(this);
        
        this.mediaController = new MediaController(this);
        this.mediaController.setAnchorView(this.videoView);
        this.mediaController.setMediaPlayer(this.videoView);
        this.videoView.setMediaController(this.mediaController);
    }
    
    @Override 
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
	    Log.d(TAG, "onRestoreInstanceState CALLED");
    	super.onRestoreInstanceState(savedInstanceState);
	}
	
	@Override
    protected void onSaveInstanceState(Bundle bundle) {
	    Log.d(TAG, "onSaveInstanceState CALLED ");
	    super.onSaveInstanceState(bundle);  
     }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart CALLED " + System.currentTimeMillis());
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart CALLED " + System.currentTimeMillis());
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume CALLED " + System.currentTimeMillis());
        this.progressBar.setVisibility(View.VISIBLE);
        this.videoPersistence.recoverState();
        Uri videoUri = Uri.parse(this.videoUrl);
        this.videoView.setVideoURI(videoUri);
    }

	/**
	* Activity docs recommend that this method be used for persistent storage.
	* SharedPreferences is used to save the current location in the current video
	*/
    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause CALLED " + System.currentTimeMillis());
        if (this.videoPlaybackComplete) {
	    	this.videoPersistence.clearState();
        } else {
        	this.videoPersistence.saveState();
        }
        this.videoView.stopPlayback();
        if (this.mediaPlayer != null) {
        	this.mediaPlayer.release();
        	this.mediaPlayer = null;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop CALLED " + System.currentTimeMillis());
    }

    @Override
    protected void onDestroy() {
	   	super.onDestroy();
        Log.d(TAG, "onDestroy CALLED " + System.currentTimeMillis());
    }

	@Override
    public void onPrepared(MediaPlayer mp) {
        Log.d(TAG, "onPrepared CALLED " + System.currentTimeMillis());
        this.mediaPlayer = mp;
        this.mediaPlayer.setOnBufferingUpdateListener(this);
	    this.videoView.start();
        if (this.currentPosition > 0) {
	       	this.mediaPlayer.setOnSeekCompleteListener(this);
	        this.videoView.seekTo(this.currentPosition);
        } else {
			this.actualStartVideo();
        }
    }
    
    public void onSeekComplete(MediaPlayer mp) {
        Log.d(TAG, "onSeekComplete CALLED " + System.currentTimeMillis());<commit_msg>Set screen on while player true<commit_after>package com.shortsands.videoplayer;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.VideoView;
/**
 * Created by garygriswold on 1/26/17.
 * This is based up the following plugin:
 * https://github.com/nchutchind/cordova-plugin-streaming-media
 */
public class VideoActivity extends Activity implements
        MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
        MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener,
        MediaPlayer.OnSeekCompleteListener, MediaPlayer.OnBufferingUpdateListener {
    private final static String TAG = "VideoActivity";
    private VideoPersistence videoPersistence = new VideoPersistence(this);
    private VideoView videoView;
    private MediaController mediaController;
    private MediaPlayer mediaPlayer;
    private ProgressBar progressBar;
    private String videoId;
    private String videoUrl;
    private int currentPosition = 0;
    private boolean videoPlaybackComplete = false;
    
    public String getVideoId() {
	    return(this.videoId);
    }
    public void setVideoId(String id) {
	    this.videoId = id;
    }
    public String getVideoUrl() {
	    return(this.videoUrl);
    }
    public void setVideoUrl(String url) {
	    this.videoUrl = url;
    }
    public int getCurrentPosition() {
	    return((this.videoView != null) ? this.videoView.getCurrentPosition() : 0);
    }
    public void setCurrentPosition(int pos) {
	    this.currentPosition = pos;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate CALLED " + System.currentTimeMillis());

        Window window = this.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setBackgroundColor(Color.BLACK);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

        this.videoView = new VideoView(this);
        this.videoView.setLayoutParams(layoutParams);
        relativeLayout.addView(this.videoView);

        // Create startup progress animation
        this.progressBar = new ProgressBar(this);
        this.progressBar.setIndeterminate(true);
        RelativeLayout.LayoutParams progLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        progLayout.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        this.progressBar.setLayoutParams(progLayout);
        relativeLayout.addView(this.progressBar);
        this.progressBar.bringToFront();

        setContentView(relativeLayout);
        
        this.videoView.setOnPreparedListener(this);
        this.videoView.setOnCompletionListener(this);
        //this.videoView.setOnInfoListener(this); requires SDK 17
        this.videoView.setOnErrorListener(this);
        
        this.mediaController = new MediaController(this);
        this.mediaController.setAnchorView(this.videoView);
        this.mediaController.setMediaPlayer(this.videoView);
        this.videoView.setMediaController(this.mediaController);
    }
    
    @Override 
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
	    Log.d(TAG, "onRestoreInstanceState CALLED");
    	super.onRestoreInstanceState(savedInstanceState);
	}
	
	@Override
    protected void onSaveInstanceState(Bundle bundle) {
	    Log.d(TAG, "onSaveInstanceState CALLED ");
	    super.onSaveInstanceState(bundle);  
     }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart CALLED " + System.currentTimeMillis());
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG, "onStart CALLED " + System.currentTimeMillis());
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume CALLED " + System.currentTimeMillis());
        this.progressBar.setVisibility(View.VISIBLE);
        this.videoPersistence.recoverState();
        Uri videoUri = Uri.parse(this.videoUrl);
        this.videoView.setVideoURI(videoUri);
    }

	/**
	* Activity docs recommend that this method be used for persistent storage.
	* SharedPreferences is used to save the current location in the current video
	*/
    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause CALLED " + System.currentTimeMillis());
        if (this.videoPlaybackComplete) {
	    	this.videoPersistence.clearState();
        } else {
        	this.videoPersistence.saveState();
        }
        this.videoView.stopPlayback();
        if (this.mediaPlayer != null) {
        	this.mediaPlayer.release();
        	this.mediaPlayer = null;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop CALLED " + System.currentTimeMillis());
    }

    @Override
    protected void onDestroy() {
	   	super.onDestroy();
        Log.d(TAG, "onDestroy CALLED " + System.currentTimeMillis());
    }

	@Override
    public void onPrepared(MediaPlayer mp) {
        Log.d(TAG, "onPrepared CALLED " + System.currentTimeMillis());
        this.mediaPlayer = mp;
        this.mediaPlayer.setScreenOnWhilePlaying(true);
        this.mediaPlayer.setOnBufferingUpdateListener(this);
	    this.videoView.start();
        if (this.currentPosition > 0) {
	       	this.mediaPlayer.setOnSeekCompleteListener(this);
	        this.videoView.seekTo(this.currentPosition);
        } else {
			this.actualStartVideo();
        }
    }
    
    public void onSeekComplete(MediaPlayer mp) {
        Log.d(TAG, "onSeekComplete CALLED " + System.currentTimeMillis());
{'fraction_non_alphanumeric': 0.09630956088445967, 'fraction_numerical': 0.0015571473061351605, 'mean_word_length': 3.326372515998653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2021812', 'n_tokens_mistral': 3686, 'n_tokens_neox': 3528, 'n_words': 671}