From c453fa1027245b8fa0e5da17ab897bb375ba804f Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Sun, 16 Dec 2012 23:14:21 +0000 Subject: [PATCH] Cancel video buffering implemented --- src/com/upc/pbe/upcnews/CustomProgressDialog.java | 31 +++++++++++++++++++++++++++++++ src/com/upc/pbe/upcnews/VideoActivity.java | 17 ++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 src/com/upc/pbe/upcnews/CustomProgressDialog.java diff --git a/src/com/upc/pbe/upcnews/CustomProgressDialog.java b/src/com/upc/pbe/upcnews/CustomProgressDialog.java new file mode 100644 index 0000000..ee9e7b0 --- /dev/null +++ b/src/com/upc/pbe/upcnews/CustomProgressDialog.java @@ -0,0 +1,31 @@ +package com.upc.pbe.upcnews; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.view.KeyEvent; + +public class CustomProgressDialog extends ProgressDialog implements DialogInterface.OnKeyListener +{ + + Activity act; + + public CustomProgressDialog(Context context) + { + super(context); + act = (Activity) context; + this.setOnKeyListener(this); + } + + public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) + { + if (keyCode == KeyEvent.KEYCODE_BACK) + { + this.dismiss(); + ((VideoActivity)act).quitPlayer(); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/VideoActivity.java b/src/com/upc/pbe/upcnews/VideoActivity.java index ce0118d..e12c66f 100644 --- a/src/com/upc/pbe/upcnews/VideoActivity.java +++ b/src/com/upc/pbe/upcnews/VideoActivity.java @@ -20,7 +20,6 @@ import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; -import android.view.KeyEvent; import android.view.View; import android.widget.Toast; @@ -38,6 +37,7 @@ public class VideoActivity extends Activity { int currentPos; boolean ended; boolean buffering; + DescarregaSegment ds; @Override @@ -101,7 +101,7 @@ public class VideoActivity extends Activity { buffering = true; if(pd == null) { - pd = new ProgressDialog(VideoActivity.this); + pd = new CustomProgressDialog(VideoActivity.this); pd.setCancelable(false); pd.setMessage(getString(R.string.buffering_text)); } @@ -116,6 +116,7 @@ public class VideoActivity extends Activity { public void quitPlayer() { + ds.cancel(true); video.stopPlayback(); super.finish(); return; @@ -179,7 +180,7 @@ public class VideoActivity extends Activity { public void downloadSegment(String url) { - DescarregaSegment ds = new DescarregaSegment(); + ds = new DescarregaSegment(); try { ds.execute(new URL(url)); @@ -201,16 +202,6 @@ public class VideoActivity extends Activity { super.onConfigurationChanged(newConfig); } - public boolean onKeyDown(int keyCode, KeyEvent event) { - // Determina el funcionament al apretar la tecla de tornar enrere - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { - toggleBuffering(false); - super.finish(); - return true; - } - return super.onKeyDown(keyCode, event); - } - public class DescarregaSegment extends AsyncTask { final static String TAG = "DescarregaSegment"; -- libgit2 0.22.2