From e19249d0ae8aeef2b9522fffb278bce82424a9b0 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Sun, 16 Dec 2012 18:38:20 +0000 Subject: [PATCH] SetDefaultQuality --- src/com/upc/pbe/upcnews/HLS.java | 66 +++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 54a6837..a717bfd 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -17,6 +17,8 @@ public class HLS private int currentQuality; // 0 es la mas alta private int currentSegment; private boolean endReached; + private int defaultQuality; + private boolean setDefault; public HLS(ArrayList parsed, String localFolder) { @@ -29,20 +31,39 @@ public class HLS Log.d(TAG, "Esborrat " + files[i].toString()); deleteme.delete(); } - - currentVideo = currentSegment = 0; + + currentVideo = currentSegment = 0; this.videos = parsed; endReached = false; + setDefault = true; } - - public void setQuality(int qual){ - currentQuality = qual; + + public void setQuality(int qual) + { + defaultQuality = qual; } - + public void loadVideo() { // Carrega la qualitat i, a partir d'aixo, el seguent segment qualities = videos.get(currentVideo++).getLists(); + if(setDefault) + { + switch (defaultQuality) + { + case 0: + currentQuality = 0; + break; + case 1: + currentQuality = (qualities.size()-1)/2; + break; + case 2: + currentQuality = qualities.size()-1; + break; + } + setDefault = true; + } + segments = qualities.get(currentQuality).getSegments(); if (currentVideo == videos.size()) { @@ -58,8 +79,7 @@ public class HLS if (endReached) { return null; - } - currentQuality = 0; + }; currentSegment = 0; loadVideo(); } @@ -67,46 +87,46 @@ public class HLS Log.d(TAG, seg.getName() + " " + seg.getURL()); return seg.getURL(); } - - + public void updateQuality(long bps) { if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1)) { int newQuality; - for(newQuality = 0; newQuality < qualities.size(); newQuality++) + for (newQuality = 0; newQuality < qualities.size(); newQuality++) { - if(bps >= qualities.get(newQuality).getQuality()) + if (bps >= qualities.get(newQuality).getQuality()) { break; } } - if(currentQuality != newQuality) + if (currentQuality != newQuality) { + setDefault = false; //Override currentQuality = newQuality; - currentVideo--; //Corregimos el del loadVideo() - loadVideo(); //Cargamos la nueva calidad + currentVideo--; // Corregimos el del loadVideo() + loadVideo(); // Cargamos la nueva calidad } } - else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1)) + else if ((bps > qualities.get(currentQuality).getQuality()) + && (bps != -1)) { int newQuality; - for(newQuality = qualities.size()-1; newQuality > 0; newQuality--) + for (newQuality = qualities.size() - 1; newQuality > 0; newQuality--) { - if(bps <= qualities.get(newQuality).getQuality()) + if (bps <= qualities.get(newQuality).getQuality()) { newQuality--; break; } } - if(currentQuality != newQuality) + if (currentQuality != newQuality) { currentQuality = newQuality; - currentVideo--; //Corregimos el del loadVideo() - loadVideo(); //Cargamos la nueva calidad + currentVideo--; // Corregimos el del loadVideo() + loadVideo(); // Cargamos la nueva calidad } } } - - + } \ No newline at end of file -- libgit2 0.22.2