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,7 +10,11 @@ import java.io.OutputStream; | ||
10 | import java.net.URL; | 10 | import java.net.URL; |
11 | import java.net.URLConnection; | 11 | import java.net.URLConnection; |
12 | 12 | ||
13 | +import android.app.DownloadManager; | ||
14 | +import android.app.DownloadManager.Request; | ||
15 | +import android.net.Uri; | ||
13 | import android.os.AsyncTask; | 16 | import android.os.AsyncTask; |
17 | +import android.os.Environment; | ||
14 | import android.util.Log; | 18 | import android.util.Log; |
15 | 19 | ||
16 | //Descarrega un arxiu i el guarda o retorna en String | 20 | //Descarrega un arxiu i el guarda o retorna en String |
@@ -18,11 +22,16 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | @@ -18,11 +22,16 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | ||
18 | { | 22 | { |
19 | final static String TAG = "Descarrega"; | 23 | final static String TAG = "Descarrega"; |
20 | private String html; | 24 | private String html; |
25 | + DownloadManager manager; | ||
21 | 26 | ||
22 | public Descarrega() | 27 | public Descarrega() |
23 | { | 28 | { |
24 | html = ""; | 29 | html = ""; |
25 | } | 30 | } |
31 | + | ||
32 | + public Descarrega(DownloadManager man){ | ||
33 | + manager = man; | ||
34 | + } | ||
26 | 35 | ||
27 | public void descarregarguardar(String url, String path) throws IOException | 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,7 +58,17 @@ public class Descarrega extends AsyncTask<Object, Object, Object> | ||
49 | out.close(); | 58 | out.close(); |
50 | in.close(); | 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,6 +4,8 @@ import java.io.IOException; | ||
4 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
5 | 5 | ||
6 | import android.app.Activity; | 6 | import android.app.Activity; |
7 | +import android.app.DownloadManager; | ||
8 | +import android.content.Context; | ||
7 | import android.content.Intent; | 9 | import android.content.Intent; |
8 | import android.os.Bundle; | 10 | import android.os.Bundle; |
9 | import android.util.Log; | 11 | import android.util.Log; |
@@ -12,9 +14,9 @@ import android.view.Menu; | @@ -12,9 +14,9 @@ import android.view.Menu; | ||
12 | import android.view.MenuItem; | 14 | import android.view.MenuItem; |
13 | import android.view.View; | 15 | import android.view.View; |
14 | import android.widget.AdapterView; | 16 | import android.widget.AdapterView; |
17 | +import android.widget.AdapterView.OnItemClickListener; | ||
15 | import android.widget.ListView; | 18 | import android.widget.ListView; |
16 | import android.widget.TextView; | 19 | import android.widget.TextView; |
17 | -import android.widget.AdapterView.OnItemClickListener; | ||
18 | import android.widget.Toast; | 20 | import android.widget.Toast; |
19 | 21 | ||
20 | //Segona Activity, mostra els directoris i arxius del servidor | 22 | //Segona Activity, mostra els directoris i arxius del servidor |
@@ -78,7 +80,8 @@ public class Directoris extends Activity implements OnItemClickListener { | @@ -78,7 +80,8 @@ public class Directoris extends Activity implements OnItemClickListener { | ||
78 | ArrayList<ParentList> m3u8parsed = p.parseFile(playlist); | 80 | ArrayList<ParentList> m3u8parsed = p.parseFile(playlist); |
79 | Log.d(TAG, "Parsing completat"); | 81 | Log.d(TAG, "Parsing completat"); |
80 | //Creem un gestor HLS | 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 | ((UpcApp)getApplication()).setHLS(h); | 85 | ((UpcApp)getApplication()).setHLS(h); |
83 | //Iniciem la reproduccio | 86 | //Iniciem la reproduccio |
84 | Intent mIntent = new Intent(this, VideoActivity.class); | 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,6 +3,8 @@ package com.upc.pbe.upcnews; | ||
3 | import java.io.File; | 3 | import java.io.File; |
4 | import java.io.IOException; | 4 | import java.io.IOException; |
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | + | ||
7 | +import android.app.DownloadManager; | ||
6 | import android.net.TrafficStats; | 8 | import android.net.TrafficStats; |
7 | import android.util.Log; | 9 | import android.util.Log; |
8 | 10 | ||
@@ -22,7 +24,8 @@ public class HLS | @@ -22,7 +24,8 @@ public class HLS | ||
22 | private Descarrega d; | 24 | private Descarrega d; |
23 | private BandwidthMeasurer bm; | 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 | // Neteja el directori i inicialitza les variables | 30 | // Neteja el directori i inicialitza les variables |
28 | File dir = new File(localFolder); | 31 | File dir = new File(localFolder); |
@@ -39,7 +42,8 @@ public class HLS | @@ -39,7 +42,8 @@ public class HLS | ||
39 | endReached = false; | 42 | endReached = false; |
40 | this.localFolder = localFolder; | 43 | this.localFolder = localFolder; |
41 | bm = new BandwidthMeasurer(); | 44 | bm = new BandwidthMeasurer(); |
42 | - d = new Descarrega(); | 45 | + |
46 | + d = new Descarrega(manager); | ||
43 | } | 47 | } |
44 | 48 | ||
45 | public void loadVideo() | 49 | public void loadVideo() |
src/com/upc/pbe/upcnews/MainActivity.java
@@ -7,12 +7,10 @@ import java.util.List; | @@ -7,12 +7,10 @@ import java.util.List; | ||
7 | 7 | ||
8 | import android.app.Activity; | 8 | import android.app.Activity; |
9 | import android.app.DownloadManager; | 9 | import android.app.DownloadManager; |
10 | -import android.app.DownloadManager.Request; | ||
11 | import android.content.Context; | 10 | import android.content.Context; |
12 | import android.content.Intent; | 11 | import android.content.Intent; |
13 | import android.content.pm.PackageInfo; | 12 | import android.content.pm.PackageInfo; |
14 | import android.content.pm.PackageManager; | 13 | import android.content.pm.PackageManager; |
15 | -import android.net.Uri; | ||
16 | import android.os.Bundle; | 14 | import android.os.Bundle; |
17 | import android.os.Environment; | 15 | import android.os.Environment; |
18 | import android.util.Log; | 16 | import android.util.Log; |
@@ -35,6 +33,7 @@ public class MainActivity extends Activity implements OnClickListener { | @@ -35,6 +33,7 @@ public class MainActivity extends Activity implements OnClickListener { | ||
35 | private TextView URLText, alertaText; | 33 | private TextView URLText, alertaText; |
36 | private boolean libsFound = false; | 34 | private boolean libsFound = false; |
37 | 35 | ||
36 | + | ||
38 | @Override | 37 | @Override |
39 | public void onCreate(Bundle savedInstanceState) | 38 | public void onCreate(Bundle savedInstanceState) |
40 | { | 39 | { |
@@ -48,14 +47,16 @@ public class MainActivity extends Activity implements OnClickListener { | @@ -48,14 +47,16 @@ public class MainActivity extends Activity implements OnClickListener { | ||
48 | Log.d(TAG,"Directori " + tempFolder.toString() + " creat"); | 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 | DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); | 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 | //Creem els botons i text | 62 | //Creem els botons i text |