Commit e19249d0ae8aeef2b9522fffb278bce82424a9b0

Authored by Imanol-Mikel Barba Sabariego
1 parent f81d71c7

SetDefaultQuality

Showing 1 changed file with 43 additions and 23 deletions
src/com/upc/pbe/upcnews/HLS.java
... ... @@ -17,6 +17,8 @@ public class HLS
17 17 private int currentQuality; // 0 es la mas alta
18 18 private int currentSegment;
19 19 private boolean endReached;
  20 + private int defaultQuality;
  21 + private boolean setDefault;
20 22  
21 23 public HLS(ArrayList<ParentList> parsed, String localFolder)
22 24 {
... ... @@ -29,20 +31,39 @@ public class HLS
29 31 Log.d(TAG, "Esborrat " + files[i].toString());
30 32 deleteme.delete();
31 33 }
32   -
33   - currentVideo = currentSegment = 0;
  34 +
  35 + currentVideo = currentSegment = 0;
34 36 this.videos = parsed;
35 37 endReached = false;
  38 + setDefault = true;
36 39 }
37   -
38   - public void setQuality(int qual){
39   - currentQuality = qual;
  40 +
  41 + public void setQuality(int qual)
  42 + {
  43 + defaultQuality = qual;
40 44 }
41   -
  45 +
42 46 public void loadVideo()
43 47 {
44 48 // Carrega la qualitat i, a partir d'aixo, el seguent segment
45 49 qualities = videos.get(currentVideo++).getLists();
  50 + if(setDefault)
  51 + {
  52 + switch (defaultQuality)
  53 + {
  54 + case 0:
  55 + currentQuality = 0;
  56 + break;
  57 + case 1:
  58 + currentQuality = (qualities.size()-1)/2;
  59 + break;
  60 + case 2:
  61 + currentQuality = qualities.size()-1;
  62 + break;
  63 + }
  64 + setDefault = true;
  65 + }
  66 +
46 67 segments = qualities.get(currentQuality).getSegments();
47 68 if (currentVideo == videos.size())
48 69 {
... ... @@ -58,8 +79,7 @@ public class HLS
58 79 if (endReached)
59 80 {
60 81 return null;
61   - }
62   - currentQuality = 0;
  82 + };
63 83 currentSegment = 0;
64 84 loadVideo();
65 85 }
... ... @@ -67,46 +87,46 @@ public class HLS
67 87 Log.d(TAG, seg.getName() + " " + seg.getURL());
68 88 return seg.getURL();
69 89 }
70   -
71   -
  90 +
72 91 public void updateQuality(long bps)
73 92 {
74 93 if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1))
75 94 {
76 95 int newQuality;
77   - for(newQuality = 0; newQuality < qualities.size(); newQuality++)
  96 + for (newQuality = 0; newQuality < qualities.size(); newQuality++)
78 97 {
79   - if(bps >= qualities.get(newQuality).getQuality())
  98 + if (bps >= qualities.get(newQuality).getQuality())
80 99 {
81 100 break;
82 101 }
83 102 }
84   - if(currentQuality != newQuality)
  103 + if (currentQuality != newQuality)
85 104 {
  105 + setDefault = false; //Override
86 106 currentQuality = newQuality;
87   - currentVideo--; //Corregimos el del loadVideo()
88   - loadVideo(); //Cargamos la nueva calidad
  107 + currentVideo--; // Corregimos el del loadVideo()
  108 + loadVideo(); // Cargamos la nueva calidad
89 109 }
90 110 }
91   - else if((bps > qualities.get(currentQuality).getQuality()) && (bps != -1))
  111 + else if ((bps > qualities.get(currentQuality).getQuality())
  112 + && (bps != -1))
92 113 {
93 114 int newQuality;
94   - for(newQuality = qualities.size()-1; newQuality > 0; newQuality--)
  115 + for (newQuality = qualities.size() - 1; newQuality > 0; newQuality--)
95 116 {
96   - if(bps <= qualities.get(newQuality).getQuality())
  117 + if (bps <= qualities.get(newQuality).getQuality())
97 118 {
98 119 newQuality--;
99 120 break;
100 121 }
101 122 }
102   - if(currentQuality != newQuality)
  123 + if (currentQuality != newQuality)
103 124 {
104 125 currentQuality = newQuality;
105   - currentVideo--; //Corregimos el del loadVideo()
106   - loadVideo(); //Cargamos la nueva calidad
  126 + currentVideo--; // Corregimos el del loadVideo()
  127 + loadVideo(); // Cargamos la nueva calidad
107 128 }
108 129 }
109 130 }
110   -
111   -
  131 +
112 132 }
113 133 \ No newline at end of file
... ...