<commit_before>package com.roryhool.videoinfoviewer.views;

import java.io.IOException;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.CountDownTimer;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView.SurfaceTextureListener;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.roryhool.videoinfoviewer.R;
import com.roryhool.videoinfoviewer.ResizeAnimation;

public class VideoPlayerView extends FrameLayout implements SurfaceTextureListener, OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener, OnVideoSizeChangedListener {

   ScaledTextureView mVideoTextureView;

   SeekBar mSeekBar;

   ImageButton mPlayButton;

   ImageButton mFullscreenButton;

   MediaPlayer mMediaPlayer;

   RelativeLayout mVideoControls;

   Uri mVideoUri;

   boolean mControlsShowing = true;

   public VideoPlayerView( Context context ) {
      super( context );
      init( context );
   }

   public VideoPlayerView( Context context, AttributeSet attrs ) {
      super( context, attrs );
      init( context );
   }

   public VideoPlayerView( Context context, AttributeSet attrs, int defStyle ) {
      super( context, attrs, defStyle );
      init( context );
   }

   private void init( Context context ) {
      addView( View.inflate( context, R.layout.video_player, null ) );

      mVideoTextureView = (ScaledTextureView) findViewById( R.id.video_texture_view );

      mVideoTextureView.addSurfaceTextureListener( this );

      mPlayButton = (ImageButton) findViewById( R.id.play_button );

      mVideoControls = (RelativeLayout) findViewById( R.id.video_controls );
      mSeekBar = (SeekBar) findViewById( R.id.seek_bar );
      mFullscreenButton = (ImageButton) findViewById( R.id.fullscreen_button );

      mSeekBar.setOnSeekBarChangeListener( mOnSeekBarChangeListener );
      mPlayButton.setOnClickListener( mOnPlayClickListener );
      mFullscreenButton.setOnClickListener( mOnFullscreenClickListener );

      this.setOnClickListener( mOnVideoPlayerViewClickListener );
   }

   public void setVideoUri( Uri videoUri ) {
      mVideoUri = videoUri;
   }
   
   OnSeekBarChangeListener mOnSeekBarChangeListener = new OnSeekBarChangeListener() {

      boolean mResumePlaying = false;

      @Override
      public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser ) {
         if ( fromUser ) {
            if ( mMediaPlayer != null ) {
               mMediaPlayer.seekTo( progress );
            }
         }
      }

      @Override
      public void onStartTrackingTouch( SeekBar seekBar ) {
         if ( mMediaPlayer != null ) {
            if ( mMediaPlayer.isPlaying() ) {
               pause();
               mResumePlaying = true;
            }
         }
      }

      @Override
      public void onStopTrackingTouch( SeekBar seekBar ) {
         if ( mResumePlaying ) {
            if ( mMediaPlayer != null ) {
               if ( !mMediaPlayer.isPlaying() ) {
                  play();
               }
            }
         }
         mResumePlaying = false;
      }

   };

   OnClickListener mOnPlayClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         if ( mMediaPlayer != null ) {
            if ( mMediaPlayer.isPlaying() ) {
               pause();
            } else {
               play();
            }
         }
      }
   };

   OnClickListener mOnVideoPlayerViewClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         if ( mControlsShowing ) {
            if ( mMediaPlayer.isPlaying() ) {
               hideControls();
            }
         } else {
            showControls();
         }
      }
   };

   OnClickListener mOnFullscreenClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         resetTimer();

         ResizeAnimation animation = null;

         int currentHeight = getHeight();
         int targetHeight = getContext().getResources().getDimensionPixelSize( R.dimen.video_player_size );

         if ( currentHeight == targetHeight ) {
            View parentView = (View) getParent();
            targetHeight = parentView.getHeight();
         }
         animation = new ResizeAnimation( VideoPlayerView.this, currentHeight, targetHeight, true );
         animation.setDuration( 200 );<commit_msg>Check if MediaPlayer is playing before resetting timer in OnFullScreenClickListener<commit_after>package com.roryhool.videoinfoviewer.views;

import java.io.IOException;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.CountDownTimer;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView.SurfaceTextureListener;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.roryhool.videoinfoviewer.R;
import com.roryhool.videoinfoviewer.ResizeAnimation;

public class VideoPlayerView extends FrameLayout implements SurfaceTextureListener, OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener, OnVideoSizeChangedListener {

   ScaledTextureView mVideoTextureView;

   SeekBar mSeekBar;

   ImageButton mPlayButton;

   ImageButton mFullscreenButton;

   MediaPlayer mMediaPlayer;

   RelativeLayout mVideoControls;

   Uri mVideoUri;

   boolean mControlsShowing = true;

   public VideoPlayerView( Context context ) {
      super( context );
      init( context );
   }

   public VideoPlayerView( Context context, AttributeSet attrs ) {
      super( context, attrs );
      init( context );
   }

   public VideoPlayerView( Context context, AttributeSet attrs, int defStyle ) {
      super( context, attrs, defStyle );
      init( context );
   }

   private void init( Context context ) {
      addView( View.inflate( context, R.layout.video_player, null ) );

      mVideoTextureView = (ScaledTextureView) findViewById( R.id.video_texture_view );

      mVideoTextureView.addSurfaceTextureListener( this );

      mPlayButton = (ImageButton) findViewById( R.id.play_button );

      mVideoControls = (RelativeLayout) findViewById( R.id.video_controls );
      mSeekBar = (SeekBar) findViewById( R.id.seek_bar );
      mFullscreenButton = (ImageButton) findViewById( R.id.fullscreen_button );

      mSeekBar.setOnSeekBarChangeListener( mOnSeekBarChangeListener );
      mPlayButton.setOnClickListener( mOnPlayClickListener );
      mFullscreenButton.setOnClickListener( mOnFullscreenClickListener );

      this.setOnClickListener( mOnVideoPlayerViewClickListener );
   }

   public void setVideoUri( Uri videoUri ) {
      mVideoUri = videoUri;
   }
   
   OnSeekBarChangeListener mOnSeekBarChangeListener = new OnSeekBarChangeListener() {

      boolean mResumePlaying = false;

      @Override
      public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser ) {
         if ( fromUser ) {
            if ( mMediaPlayer != null ) {
               mMediaPlayer.seekTo( progress );
            }
         }
      }

      @Override
      public void onStartTrackingTouch( SeekBar seekBar ) {
         if ( mMediaPlayer != null ) {
            if ( mMediaPlayer.isPlaying() ) {
               pause();
               mResumePlaying = true;
            }
         }
      }

      @Override
      public void onStopTrackingTouch( SeekBar seekBar ) {
         if ( mResumePlaying ) {
            if ( mMediaPlayer != null ) {
               if ( !mMediaPlayer.isPlaying() ) {
                  play();
               }
            }
         }
         mResumePlaying = false;
      }

   };

   OnClickListener mOnPlayClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         if ( mMediaPlayer != null ) {
            if ( mMediaPlayer.isPlaying() ) {
               pause();
            } else {
               play();
            }
         }
      }
   };

   OnClickListener mOnVideoPlayerViewClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         if ( mControlsShowing ) {
            if ( mMediaPlayer.isPlaying() ) {
               hideControls();
            }
         } else {
            showControls();
         }
      }
   };

   OnClickListener mOnFullscreenClickListener = new OnClickListener() {
      @Override
      public void onClick( View view ) {
         if ( mMediaPlayer.isPlaying() ) {
            resetTimer();
         }

         ResizeAnimation animation = null;

         int currentHeight = getHeight();
         int targetHeight = getContext().getResources().getDimensionPixelSize( R.dimen.video_player_size );

         if ( currentHeight == targetHeight ) {
            View parentView = (View) getParent();
            targetHeight = parentView.getHeight();
         }
         animation = new ResizeAnimation( VideoPlayerView.this, currentHeight, targetHeight, true );
         animation.setDuration( 200 );
{'fraction_non_alphanumeric': 0.08299774088989294, 'fraction_numerical': 0.0005893330714075238, 'mean_word_length': 2.7739065974796144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4266510', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2652, 'n_words': 583}