3131import android .os .Looper ;
3232import android .os .Message ;
3333import android .util .Log ;
34+ import android .view .KeyEvent ;
35+ import android .view .View ;
3436
3537import java .io .ByteArrayOutputStream ;
3638import java .io .IOException ;
@@ -47,7 +49,8 @@ class HTML5VideoViewProxy extends Handler
4749 MediaPlayer .OnCompletionListener ,
4850 MediaPlayer .OnErrorListener ,
4951 MediaPlayer .OnInfoListener ,
50- SurfaceTexture .OnFrameAvailableListener {
52+ SurfaceTexture .OnFrameAvailableListener ,
53+ View .OnKeyListener {
5154 // Logging tag.
5255 private static final String LOGTAG = "HTML5VideoViewProxy" ;
5356
@@ -94,9 +97,6 @@ private static final class VideoPlayer {
9497 private static HTML5VideoView mHTML5VideoView ;
9598
9699 private static boolean isVideoSelfEnded = false ;
97- // By using the baseLayer and the current video Layer ID, we can
98- // identify the exact layer on the UI thread to use the SurfaceTexture.
99- private static int mBaseLayer = 0 ;
100100
101101 private static void setPlayerBuffering (boolean playerBuffering ) {
102102 mHTML5VideoView .setPlayerBuffering (playerBuffering );
@@ -106,7 +106,6 @@ private static void setPlayerBuffering(boolean playerBuffering) {
106106 // When we found the Video layer, then we set the Surface Texture to it.
107107 // Otherwise, we may want to delete the Surface Texture to save memory.
108108 public static void setBaseLayer (int layer ) {
109- mBaseLayer = layer ;
110109 // Don't do this for full screen mode.
111110 if (mHTML5VideoView != null
112111 && !mHTML5VideoView .isFullScreenMode ()
@@ -303,6 +302,7 @@ public static void end() {
303302
304303 // A bunch event listeners for our VideoView
305304 // MediaPlayer.OnPreparedListener
305+ @ Override
306306 public void onPrepared (MediaPlayer mp ) {
307307 VideoPlayer .onPrepared ();
308308 Message msg = Message .obtain (mWebCoreHandler , PREPARED );
@@ -315,6 +315,7 @@ public void onPrepared(MediaPlayer mp) {
315315 }
316316
317317 // MediaPlayer.OnCompletionListener;
318+ @ Override
318319 public void onCompletion (MediaPlayer mp ) {
319320 // The video ended by itself, so we need to
320321 // send a message to the UI thread to dismiss
@@ -324,6 +325,7 @@ public void onCompletion(MediaPlayer mp) {
324325 }
325326
326327 // MediaPlayer.OnErrorListener
328+ @ Override
327329 public boolean onError (MediaPlayer mp , int what , int extra ) {
328330 sendMessage (obtainMessage (ERROR ));
329331 return false ;
@@ -489,24 +491,28 @@ public void cancelAndReleaseQueue() {
489491 releaseQueue ();
490492 }
491493 // EventHandler methods. Executed on the network thread.
494+ @ Override
492495 public void status (int major_version ,
493496 int minor_version ,
494497 int code ,
495498 String reason_phrase ) {
496499 mStatusCode = code ;
497500 }
498501
502+ @ Override
499503 public void headers (Headers headers ) {
500504 mHeaders = headers ;
501505 }
502506
507+ @ Override
503508 public void data (byte [] data , int len ) {
504509 if (mPosterBytes == null ) {
505510 mPosterBytes = new ByteArrayOutputStream ();
506511 }
507512 mPosterBytes .write (data , 0 , len );
508513 }
509514
515+ @ Override
510516 public void endData () {
511517 if (mStatusCode == 200 ) {
512518 if (mPosterBytes .size () > 0 ) {
@@ -524,6 +530,7 @@ public void endData() {
524530 }
525531 if (mUrl != null ) {
526532 mHandler .post (new Runnable () {
533+ @ Override
527534 public void run () {
528535 if (mRequestHandle != null ) {
529536 mRequestHandle .setupRedirect (mUrl .toString (), mStatusCode ,
@@ -535,14 +542,17 @@ public void run() {
535542 }
536543 }
537544
545+ @ Override
538546 public void certificate (SslCertificate certificate ) {
539547 // Don't care.
540548 }
541549
550+ @ Override
542551 public void error (int id , String description ) {
543552 cleanup ();
544553 }
545554
555+ @ Override
546556 public boolean handleSslErrorRequest (SslError error ) {
547557 // Don't care. If this happens, data() will never be called so
548558 // mPosterBytes will never be created, so no need to call cleanup.
@@ -794,4 +804,17 @@ public boolean onInfo(MediaPlayer mp, int what, int extra) {
794804 }
795805 return false ;
796806 }
807+
808+ @ Override
809+ public boolean onKey (View v , int keyCode , KeyEvent event ) {
810+ if (keyCode == KeyEvent .KEYCODE_BACK ) {
811+ if (event .getAction () == KeyEvent .ACTION_DOWN ) {
812+ return true ;
813+ } else if (event .getAction () == KeyEvent .ACTION_UP && !event .isCanceled ()) {
814+ VideoPlayer .exitFullScreenVideo (this , mWebView );
815+ return true ;
816+ }
817+ }
818+ return false ;
819+ }
797820}
0 commit comments