Commit d9071b7611020671bee2c9cf80828f7f6e4bf532
1 parent
26031db4
--no commit message
Showing
4 changed files
with
40 additions
and
13 deletions
src/com/upc/pbe/upcnews/Descarrega.java
... | ... | @@ -10,7 +10,11 @@ import java.io.OutputStream; |
10 | 10 | import java.net.URL; |
11 | 11 | import java.net.URLConnection; |
12 | 12 | |
13 | +import android.app.DownloadManager; | |
14 | +import android.app.DownloadManager.Request; | |
15 | +import android.net.Uri; | |
13 | 16 | import android.os.AsyncTask; |
17 | +import android.os.Environment; | |
14 | 18 | import android.util.Log; |
15 | 19 | |
16 | 20 | //Descarrega un arxiu i el guarda o retorna en String |
... | ... | @@ -18,11 +22,16 @@ public class Descarrega extends AsyncTask<Object, Object, Object> |
18 | 22 | { |
19 | 23 | final static String TAG = "Descarrega"; |
20 | 24 | private String html; |
25 | + DownloadManager manager; | |
21 | 26 | |
22 | 27 | public Descarrega() |
23 | 28 | { |
24 | 29 | html = ""; |
25 | 30 | } |
31 | + | |
32 | + public Descarrega(DownloadManager man){ | |
33 | + manager = man; | |
34 | + } | |
26 | 35 | |
27 | 36 | public void descarregarguardar(String url, String path) throws IOException |
28 | 37 | { |
... | ... | @@ -49,7 +58,17 @@ public class Descarrega extends AsyncTask<Object, Object, Object> |
49 | 58 | out.close(); |
50 | 59 | in.close(); |
51 | 60 | |
61 | + } | |
52 | 62 | |
63 | + public void descarrega(String url, String path, String name) throws IOException{ | |
64 | + | |
65 | + Request req = new Request(Uri.parse(url)); | |
66 | + | |
67 | + //req.setVisibleInDownloadsUi(false); | |
68 | + req.setDestinationInExternalPublicDir(path, name); | |
69 | + manager.enqueue(req); | |
70 | + Log.d(TAG, "\nDescarregant: \n"); | |
71 | + Log.d(TAG, " >> URL: " + url + " >> Desti: " + path); | |
53 | 72 | |
54 | 73 | } |
55 | 74 | ... | ... |
src/com/upc/pbe/upcnews/Directoris.java
... | ... | @@ -4,6 +4,8 @@ import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | |
6 | 6 | import android.app.Activity; |
7 | +import android.app.DownloadManager; | |
8 | +import android.content.Context; | |
7 | 9 | import android.content.Intent; |
8 | 10 | import android.os.Bundle; |
9 | 11 | import android.util.Log; |
... | ... | @@ -12,9 +14,9 @@ import android.view.Menu; |
12 | 14 | import android.view.MenuItem; |
13 | 15 | import android.view.View; |
14 | 16 | import android.widget.AdapterView; |
17 | +import android.widget.AdapterView.OnItemClickListener; | |
15 | 18 | import android.widget.ListView; |
16 | 19 | import android.widget.TextView; |
17 | -import android.widget.AdapterView.OnItemClickListener; | |
18 | 20 | import android.widget.Toast; |
19 | 21 | |
20 | 22 | //Segona Activity, mostra els directoris i arxius del servidor |
... | ... | @@ -78,7 +80,8 @@ public class Directoris extends Activity implements OnItemClickListener { |
78 | 80 | ArrayList<ParentList> m3u8parsed = p.parseFile(playlist); |
79 | 81 | Log.d(TAG, "Parsing completat"); |
80 | 82 | //Creem un gestor HLS |
81 | - HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); | |
83 | + DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); | |
84 | + HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath(), manager); | |
82 | 85 | ((UpcApp)getApplication()).setHLS(h); |
83 | 86 | //Iniciem la reproduccio |
84 | 87 | Intent mIntent = new Intent(this, VideoActivity.class); | ... | ... |
src/com/upc/pbe/upcnews/HLS.java
... | ... | @@ -3,6 +3,8 @@ package com.upc.pbe.upcnews; |
3 | 3 | import java.io.File; |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.util.ArrayList; |
6 | + | |
7 | +import android.app.DownloadManager; | |
6 | 8 | import android.net.TrafficStats; |
7 | 9 | import android.util.Log; |
8 | 10 | |
... | ... | @@ -22,7 +24,8 @@ public class HLS |
22 | 24 | private Descarrega d; |
23 | 25 | private BandwidthMeasurer bm; |
24 | 26 | |
25 | - public HLS(ArrayList<ParentList> parsed, String localFolder) | |
27 | + | |
28 | + public HLS(ArrayList<ParentList> parsed, String localFolder, DownloadManager manager) | |
26 | 29 | { |
27 | 30 | // Neteja el directori i inicialitza les variables |
28 | 31 | File dir = new File(localFolder); |
... | ... | @@ -39,7 +42,8 @@ public class HLS |
39 | 42 | endReached = false; |
40 | 43 | this.localFolder = localFolder; |
41 | 44 | bm = new BandwidthMeasurer(); |
42 | - d = new Descarrega(); | |
45 | + | |
46 | + d = new Descarrega(manager); | |
43 | 47 | } |
44 | 48 | |
45 | 49 | public void loadVideo() | ... | ... |
src/com/upc/pbe/upcnews/MainActivity.java
... | ... | @@ -7,12 +7,10 @@ import java.util.List; |
7 | 7 | |
8 | 8 | import android.app.Activity; |
9 | 9 | import android.app.DownloadManager; |
10 | -import android.app.DownloadManager.Request; | |
11 | 10 | import android.content.Context; |
12 | 11 | import android.content.Intent; |
13 | 12 | import android.content.pm.PackageInfo; |
14 | 13 | import android.content.pm.PackageManager; |
15 | -import android.net.Uri; | |
16 | 14 | import android.os.Bundle; |
17 | 15 | import android.os.Environment; |
18 | 16 | import android.util.Log; |
... | ... | @@ -35,6 +33,7 @@ public class MainActivity extends Activity implements OnClickListener { |
35 | 33 | private TextView URLText, alertaText; |
36 | 34 | private boolean libsFound = false; |
37 | 35 | |
36 | + | |
38 | 37 | @Override |
39 | 38 | public void onCreate(Bundle savedInstanceState) |
40 | 39 | { |
... | ... | @@ -48,14 +47,16 @@ public class MainActivity extends Activity implements OnClickListener { |
48 | 47 | Log.d(TAG,"Directori " + tempFolder.toString() + " creat"); |
49 | 48 | } |
50 | 49 | |
51 | - String url = "http://revistes.upc.es/~imanol/PBE/sample_ep_128k-00001.ts"; | |
52 | - Request req = new Request(Uri.parse(url)); | |
53 | - req.setTitle("TestTitle"); | |
54 | - req.setDescription("TestDescription"); | |
55 | - //req.setVisibleInDownloadsUi(false); | |
56 | - req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "a.ts"); | |
50 | + //Prova descarrega | |
57 | 51 | DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); |
58 | - manager.enqueue(req); | |
52 | + Descarrega desc = new Descarrega(manager); | |
53 | + try { | |
54 | + desc.descarrega("http://revistes.upc.es/~imanol/PBE/sample_ep_128k-00004.ts", Environment.DIRECTORY_DOWNLOADS, "marc.ts"); | |
55 | + } catch (IOException e) { | |
56 | + e.printStackTrace(); | |
57 | + } | |
58 | + | |
59 | + | |
59 | 60 | |
60 | 61 | |
61 | 62 | //Creem els botons i text | ... | ... |