Commit c453fa1027245b8fa0e5da17ab897bb375ba804f
1 parent
2ad5a7ce
Cancel video buffering implemented
Showing
2 changed files
with
35 additions
and
13 deletions
src/com/upc/pbe/upcnews/CustomProgressDialog.java
0 → 100644
1 | +package com.upc.pbe.upcnews; | ||
2 | + | ||
3 | +import android.app.Activity; | ||
4 | +import android.app.ProgressDialog; | ||
5 | +import android.content.Context; | ||
6 | +import android.content.DialogInterface; | ||
7 | +import android.view.KeyEvent; | ||
8 | + | ||
9 | +public class CustomProgressDialog extends ProgressDialog implements DialogInterface.OnKeyListener | ||
10 | +{ | ||
11 | + | ||
12 | + Activity act; | ||
13 | + | ||
14 | + public CustomProgressDialog(Context context) | ||
15 | + { | ||
16 | + super(context); | ||
17 | + act = (Activity) context; | ||
18 | + this.setOnKeyListener(this); | ||
19 | + } | ||
20 | + | ||
21 | + public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) | ||
22 | + { | ||
23 | + if (keyCode == KeyEvent.KEYCODE_BACK) | ||
24 | + { | ||
25 | + this.dismiss(); | ||
26 | + ((VideoActivity)act).quitPlayer(); | ||
27 | + return true; | ||
28 | + } | ||
29 | + return false; | ||
30 | + } | ||
31 | +} | ||
0 | \ No newline at end of file | 32 | \ No newline at end of file |
src/com/upc/pbe/upcnews/VideoActivity.java
@@ -20,7 +20,6 @@ import android.net.TrafficStats; | @@ -20,7 +20,6 @@ import android.net.TrafficStats; | ||
20 | import android.os.AsyncTask; | 20 | import android.os.AsyncTask; |
21 | import android.os.Bundle; | 21 | import android.os.Bundle; |
22 | import android.util.Log; | 22 | import android.util.Log; |
23 | -import android.view.KeyEvent; | ||
24 | import android.view.View; | 23 | import android.view.View; |
25 | import android.widget.Toast; | 24 | import android.widget.Toast; |
26 | 25 | ||
@@ -38,6 +37,7 @@ public class VideoActivity extends Activity { | @@ -38,6 +37,7 @@ public class VideoActivity extends Activity { | ||
38 | int currentPos; | 37 | int currentPos; |
39 | boolean ended; | 38 | boolean ended; |
40 | boolean buffering; | 39 | boolean buffering; |
40 | + DescarregaSegment ds; | ||
41 | 41 | ||
42 | 42 | ||
43 | @Override | 43 | @Override |
@@ -101,7 +101,7 @@ public class VideoActivity extends Activity { | @@ -101,7 +101,7 @@ public class VideoActivity extends Activity { | ||
101 | buffering = true; | 101 | buffering = true; |
102 | if(pd == null) | 102 | if(pd == null) |
103 | { | 103 | { |
104 | - pd = new ProgressDialog(VideoActivity.this); | 104 | + pd = new CustomProgressDialog(VideoActivity.this); |
105 | pd.setCancelable(false); | 105 | pd.setCancelable(false); |
106 | pd.setMessage(getString(R.string.buffering_text)); | 106 | pd.setMessage(getString(R.string.buffering_text)); |
107 | } | 107 | } |
@@ -116,6 +116,7 @@ public class VideoActivity extends Activity { | @@ -116,6 +116,7 @@ public class VideoActivity extends Activity { | ||
116 | 116 | ||
117 | public void quitPlayer() | 117 | public void quitPlayer() |
118 | { | 118 | { |
119 | + ds.cancel(true); | ||
119 | video.stopPlayback(); | 120 | video.stopPlayback(); |
120 | super.finish(); | 121 | super.finish(); |
121 | return; | 122 | return; |
@@ -179,7 +180,7 @@ public class VideoActivity extends Activity { | @@ -179,7 +180,7 @@ public class VideoActivity extends Activity { | ||
179 | 180 | ||
180 | public void downloadSegment(String url) | 181 | public void downloadSegment(String url) |
181 | { | 182 | { |
182 | - DescarregaSegment ds = new DescarregaSegment(); | 183 | + ds = new DescarregaSegment(); |
183 | try | 184 | try |
184 | { | 185 | { |
185 | ds.execute(new URL(url)); | 186 | ds.execute(new URL(url)); |
@@ -201,16 +202,6 @@ public class VideoActivity extends Activity { | @@ -201,16 +202,6 @@ public class VideoActivity extends Activity { | ||
201 | super.onConfigurationChanged(newConfig); | 202 | super.onConfigurationChanged(newConfig); |
202 | } | 203 | } |
203 | 204 | ||
204 | - public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
205 | - // Determina el funcionament al apretar la tecla de tornar enrere | ||
206 | - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { | ||
207 | - toggleBuffering(false); | ||
208 | - super.finish(); | ||
209 | - return true; | ||
210 | - } | ||
211 | - return super.onKeyDown(keyCode, event); | ||
212 | - } | ||
213 | - | ||
214 | public class DescarregaSegment extends AsyncTask<URL, Void, Void> | 205 | public class DescarregaSegment extends AsyncTask<URL, Void, Void> |
215 | { | 206 | { |
216 | final static String TAG = "DescarregaSegment"; | 207 | final static String TAG = "DescarregaSegment"; |