diff --git a/src/com/upc/pbe/upcnews/BandwidthMeasurer.java b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java index 5954b12..dbf968d 100644 --- a/src/com/upc/pbe/upcnews/BandwidthMeasurer.java +++ b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java @@ -1,17 +1,21 @@ package com.upc.pbe.upcnews; import android.net.TrafficStats; +import android.util.Log; //Mesura la velocitat (Bandwidth) d'Internet public class BandwidthMeasurer { - public double Measure(long rxBytes, long Time){ + private final static String TAG = "Measurer"; + public double Measure(long rxBytes, long Time) + { long AfterTime = System.currentTimeMillis(); double bps; long TotalRxAfterTest = TrafficStats.getTotalRxBytes(); double TimeDifference = AfterTime - Time; double rxDiff = TotalRxAfterTest - rxBytes; - + Log.d(TAG,"Time difference = " + TimeDifference/1000); + Log.d(TAG, "Bytes difference = " + rxDiff); if(rxDiff != 0){ bps = ((rxDiff*8) / (TimeDifference/1000)); // total rx bits per second. } diff --git a/src/com/upc/pbe/upcnews/Descarrega.java b/src/com/upc/pbe/upcnews/Descarrega.java index 05597d8..964ed27 100644 --- a/src/com/upc/pbe/upcnews/Descarrega.java +++ b/src/com/upc/pbe/upcnews/Descarrega.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -15,72 +14,60 @@ import android.os.AsyncTask; import android.util.Log; //Descarrega un arxiu i el guarda o retorna en String -public class Descarrega extends AsyncTask { - +public class Descarrega extends AsyncTask +{ + final static String TAG = "Descarrega"; - private String url, carpeta, nomarxiu, html; - private File arxiu; + private String html; - public Descarrega() { - nomarxiu = "ejemplo.xml"; - carpeta = "Environment.getExternalStorageDirectory.getPath()"; - this.carpeta = null; - this.html = ""; - this.arxiu = null; + public Descarrega() + { + html = ""; } - public void descarregarguardar(String u, String nom, String car) { - //Descarrega un arxiu i el guarda - this.nomarxiu = nom; - this.carpeta = car; - this.url = u; - //Creem el directori - File dir = new File(carpeta); - if (!dir.exists()) { - if (!dir.mkdir()) { - return; // No s'ha pogut crear (ja existeix) - } - } - //Creem l'arxiu - arxiu = new File(carpeta + nomarxiu); - //Iniciem la descarrega - try { - URLConnection conn = new URL(url).openConnection(); - conn.connect(); - Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, " >> URL: " + url + " >> Nom: " + nomarxiu - + " >> Tamany: " + conn.getContentLength() + " bytes"); - //Llegeix cada byte i l'escriu en un arxiu fins que arriba a -1 - InputStream in = conn.getInputStream(); - OutputStream out = new FileOutputStream(arxiu); - int b = 0; - while (b != -1) { - b = in.read(); - if (b != -1) { - out.write(b); - } + public long descarregarguardar(String url, String path) throws IOException + { + // Descarrega un arxiu i el guarda + // Creem l'arxiu + File file = new File(path + url.substring(url.lastIndexOf("/")+1, url.length())); + // Iniciem la descarrega + + URLConnection conn = new URL(url).openConnection(); + conn.connect(); + Log.d(TAG, "\nDescarregant: \n"); + Log.d(TAG, " >> URL: " + url + " >> Desti: " + path + " >> Tamany: " + + conn.getContentLength() + " bytes"); + // Llegeix cada byte i l'escriu en un arxiu fins que arriba a -1 + InputStream in = conn.getInputStream(); + OutputStream out = new FileOutputStream(file); + int b = 0; + while (b != -1) + { + b = in.read(); + if (b != -1) + { + out.write(b); } - out.close(); - in.close(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } + out.close(); + in.close(); + return conn.getContentLength(); } - protected String doInBackground(String u) throws IOException { - //Descarrega un arxiu i el retorna en un String - this.url = u; + protected String doInBackground(String url) throws IOException + { + // Descarrega un arxiu i el retorna en un String html = ""; - //Iniciem la connexió i creem els Streams + // Iniciem la connexi� i creem els Streams URLConnection conn = new URL(url).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); - //Iniciem la descarrega i anem guardant al String + // Iniciem la descarrega i anem guardant al String Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, ">> URL: " + url + " >> Tamany: " + conn.getContentLength()+ " bytes"); + Log.d(TAG, ">> URL: " + url + " >> Tamany: " + conn.getContentLength() + + " bytes"); String inputLine; - while ((inputLine = in.readLine()) != null) { + while ((inputLine = in.readLine()) != null) + { html = html + "\n" + inputLine; } Log.d(TAG, "Descarrega finalitzada"); @@ -89,8 +76,9 @@ public class Descarrega extends AsyncTask { } @Override - protected Object doInBackground(Object... arg0) { - //Metode Overrided, no te utilitat + protected Object doInBackground(Object... arg0) + { + // Metode Overrided, no te utilitat return null; } } diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 836757e..c3ae117 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -1,25 +1,27 @@ package com.upc.pbe.upcnews; - import java.io.File; +import java.io.IOException; import java.util.ArrayList; + +import android.net.TrafficStats; import android.util.Log; //Gestor del protocol HTTP Live Streaming -public class HLS +public class HLS { private static final String TAG = "HLS"; private ArrayList videos; private ArrayList segments; private ArrayList