Commit 58c38b154379898e31ee899508f45c7022d649f2

Authored by Imanol-Mikel Barba Sabariego
1 parent e7ab16fe

primer intento de reproducir: FAIL

src/com/upc/pbe/upcnews/Directoris.java
... ... @@ -4,7 +4,9 @@ import java.io.IOException;
4 4 import java.util.ArrayList;
5 5  
6 6 import android.app.Activity;
  7 +import android.content.ComponentName;
7 8 import android.content.Intent;
  9 +import android.net.Uri;
8 10 import android.os.Bundle;
9 11 import android.util.Log;
10 12 import android.view.KeyEvent;
... ... @@ -76,7 +78,21 @@ public class Directoris extends Activity implements OnItemClickListener {
76 78 ArrayList<ParentList> m3u8parsed = p.parseFile(playlist);
77 79 Log.d(TAG, "parsing completed");
78 80 HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath());
79   - h.start();
  81 + h.loadVideo();
  82 + /*
  83 + * while(true)
  84 + * {
  85 + * String[] segment = h.next();
  86 + * if(segment == null)
  87 + * {
  88 + * break;
  89 + * }
  90 + * Log.d(TAG,segment[0]);
  91 + * startPlayer(segment[0],segment[1]);
  92 + */
  93 + String[] test = {"/sdcard/a.ts","LE TEST"};
  94 + startPlayer(test[0],test[1]);
  95 +
80 96 }
81 97 catch (ErrorException e){
82 98 Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
... ... @@ -108,29 +124,15 @@ public class Directoris extends Activity implements OnItemClickListener {
108 124 }
109 125 }
110 126  
111   - public boolean onCreateOptionsMenu(Menu menu){
112   - //Determina el funcionament al apretar la tecla d'opcions
113   - getMenuInflater().inflate(R.menu.menu, menu);
114   - Log.d(TAG, "Menu");
115   - return true;
  127 + private void startPlayer(String url, String title) {
  128 + Intent i = new Intent();
  129 + i.setComponent(new ComponentName("me.abitno.vplayer.t", "me.abitno.vplayer.VideoActivity"));
  130 + i.setAction("me.abitno.vplayer.action.VIEW");
  131 + i.setData(Uri.parse(url));
  132 + i.putExtra("displayName", title);
  133 + startActivity(i);
116 134 }
117   -
118   - public boolean onOptionsItemSelected(MenuItem item){
119   - //Determina el funcionament al clickar en el menu d'opcions
120   - switch (item.getItemId()){
121   - case R.id.itemprefs:
122   - startActivity(new Intent(this, Prefs.class));
123   - Log.d(TAG, "Preferences");
124   - return true;
125   - case R.id.itemhelp:
126   - startActivity(new Intent(this, Help.class));
127   - Log.d(TAG, "Help");
128   - return true;
129   - default:
130   - return false;
131   - }
132   - }
133   -
  135 +
134 136 public boolean onKeyDown(int keyCode, KeyEvent event) {
135 137 //Determina el funcionament al apretar la tecla de tornar enrere
136 138 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
... ...
src/com/upc/pbe/upcnews/HLS.java
... ... @@ -2,6 +2,9 @@ package com.upc.pbe.upcnews;
2 2  
3 3 import java.util.ArrayList;
4 4  
  5 +import android.content.ComponentName;
  6 +import android.content.Intent;
  7 +import android.net.Uri;
5 8 import android.util.Log;
6 9  
7 10 //Gestor del protocol HTTP Live Streaming
... ... @@ -9,6 +12,8 @@ public class HLS {
9 12  
10 13 private static final String TAG = "HLS";
11 14 private ArrayList<ParentList> videos;
  15 + private ArrayList<Segment> segments;
  16 + private ArrayList<Video> qualities;
12 17 private int currentVideo ;
13 18 private int currentQuality; //0 es la mas alta
14 19 private int currentSegment;
... ... @@ -25,31 +30,39 @@ public class HLS {
25 30 bm = new BandwidthMeasurer();
26 31 }
27 32  
28   - public void start(){
29   - for(currentVideo = 0; currentVideo < videos.size(); currentVideo++){
30   - ArrayList<Video> qualities = videos.get(currentVideo++).getLists();
31   - while(!endReached){
32   - ArrayList<Segment> segments = qualities.get(currentQuality).getSegments();
33   - while(true){
34   - Segment seg = segments.get(currentSegment++);
35   - Log.d(TAG, seg.getName() + " " + seg.getURL());
36   - long startTime = System.currentTimeMillis();
37   - //long segmentBytes = fd.Download(seg.getURL(),localFolder);
38   - long segmentBytes = 0;
39   - double bps = bm.Measure(segmentBytes,startTime);
40   - if((bps < qualities.get(currentQuality).getQuality()) && (bps != -1)){
41   - currentQuality++;
42   - break;
43   - }
44   - /*
45   - * REPRODUCIR SEGMENTO
46   - */
47   - if(currentSegment == segments.size()){
48   - endReached = true;
49   - break;
50   - }
51   - }
52   - }
  33 + public void loadVideo()
  34 + {
  35 + qualities = videos.get(currentVideo++).getLists();
  36 + segments = qualities.get(currentQuality).getSegments();
  37 + if(currentVideo == videos.size())
  38 + {
  39 + endReached = true;
53 40 }
54 41 }
  42 +
  43 + public String[] next()
  44 + {
  45 + Segment seg = segments.get(currentSegment++);
  46 + Log.d(TAG, seg.getName() + " " + seg.getURL());
  47 + long startTime = System.currentTimeMillis();
  48 + //long segmentBytes = fd.Download(seg.getURL(),localFolder);
  49 + long segmentBytes = 0;
  50 + double bps = bm.Measure(segmentBytes,startTime);
  51 + if((bps < qualities.get(currentQuality).getQuality()) && (bps != -1))
  52 + {
  53 + currentQuality++;
  54 + }
  55 + String[] data = new String[2];
  56 + data[0] = seg.getURL().substring(seg.getURL().lastIndexOf("/")+2, seg.getURL().length());
  57 + data[1] = seg.getName();
  58 + if(currentSegment == segments.size())
  59 + {
  60 + if(endReached)
  61 + {
  62 + return null;
  63 + }
  64 + loadVideo();
  65 + }
  66 + return data;
  67 + }
55 68 }
56 69 \ No newline at end of file
... ...