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 | 32 | \ No newline at end of file | ... | ... |
src/com/upc/pbe/upcnews/VideoActivity.java
... | ... | @@ -20,7 +20,6 @@ import android.net.TrafficStats; |
20 | 20 | import android.os.AsyncTask; |
21 | 21 | import android.os.Bundle; |
22 | 22 | import android.util.Log; |
23 | -import android.view.KeyEvent; | |
24 | 23 | import android.view.View; |
25 | 24 | import android.widget.Toast; |
26 | 25 | |
... | ... | @@ -38,6 +37,7 @@ public class VideoActivity extends Activity { |
38 | 37 | int currentPos; |
39 | 38 | boolean ended; |
40 | 39 | boolean buffering; |
40 | + DescarregaSegment ds; | |
41 | 41 | |
42 | 42 | |
43 | 43 | @Override |
... | ... | @@ -101,7 +101,7 @@ public class VideoActivity extends Activity { |
101 | 101 | buffering = true; |
102 | 102 | if(pd == null) |
103 | 103 | { |
104 | - pd = new ProgressDialog(VideoActivity.this); | |
104 | + pd = new CustomProgressDialog(VideoActivity.this); | |
105 | 105 | pd.setCancelable(false); |
106 | 106 | pd.setMessage(getString(R.string.buffering_text)); |
107 | 107 | } |
... | ... | @@ -116,6 +116,7 @@ public class VideoActivity extends Activity { |
116 | 116 | |
117 | 117 | public void quitPlayer() |
118 | 118 | { |
119 | + ds.cancel(true); | |
119 | 120 | video.stopPlayback(); |
120 | 121 | super.finish(); |
121 | 122 | return; |
... | ... | @@ -179,7 +180,7 @@ public class VideoActivity extends Activity { |
179 | 180 | |
180 | 181 | public void downloadSegment(String url) |
181 | 182 | { |
182 | - DescarregaSegment ds = new DescarregaSegment(); | |
183 | + ds = new DescarregaSegment(); | |
183 | 184 | try |
184 | 185 | { |
185 | 186 | ds.execute(new URL(url)); |
... | ... | @@ -201,16 +202,6 @@ public class VideoActivity extends Activity { |
201 | 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 | 205 | public class DescarregaSegment extends AsyncTask<URL, Void, Void> |
215 | 206 | { |
216 | 207 | final static String TAG = "DescarregaSegment"; | ... | ... |