From 90ebde3da40b6eae4f569615c7d819d3a8bd8064 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Mon, 10 Dec 2012 00:26:45 +0000 Subject: [PATCH] Improves varios --- src/com/upc/pbe/upcnews/BandwidthMeasurer.java | 4 ++-- src/com/upc/pbe/upcnews/Directoris.java | 30 +++++++++--------------------- src/com/upc/pbe/upcnews/HLS.java | 32 ++++++++++++++++++++++---------- src/com/upc/pbe/upcnews/UpcApp.java | 11 +++++++++++ src/com/upc/pbe/upcnews/VideoActivity.java | 40 ++++++++++++++++++++++++++++++++-------- 5 files changed, 76 insertions(+), 41 deletions(-) diff --git a/src/com/upc/pbe/upcnews/BandwidthMeasurer.java b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java index c9f6675..5954b12 100644 --- a/src/com/upc/pbe/upcnews/BandwidthMeasurer.java +++ b/src/com/upc/pbe/upcnews/BandwidthMeasurer.java @@ -3,8 +3,8 @@ package com.upc.pbe.upcnews; import android.net.TrafficStats; //Mesura la velocitat (Bandwidth) d'Internet -public class BandwidthMeasurer{ - +public class BandwidthMeasurer +{ public double Measure(long rxBytes, long Time){ long AfterTime = System.currentTimeMillis(); double bps; diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index 368f1f5..ca35cbd 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -4,9 +4,7 @@ import java.io.IOException; import java.util.ArrayList; import android.app.Activity; -import android.content.ComponentName; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; @@ -24,7 +22,6 @@ public class Directoris extends Activity implements OnItemClickListener { private Descarrega d = new Descarrega(); private String URL, currentFolder; private HTMLParser parser; - private VideoActivity videoPlayer; public void onCreate(Bundle savedInstanceState){ //Creem el layout @@ -39,7 +36,6 @@ public class Directoris extends Activity implements OnItemClickListener { parser = new HTMLParser(URL); //Fem una llista ListView i la omplim amb la informacio trobada ((ListView)findViewById(R.id.listView1)).setOnItemClickListener(this); - videoPlayer = new VideoActivity(); this.showResources(); } @@ -78,24 +74,16 @@ public class Directoris extends Activity implements OnItemClickListener { ArrayList m3u8parsed = p.parseFile(playlist); Log.d(TAG, "parsing completed"); HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath()); - h.loadVideo(); - /* - * while(true) - * { - * String[] segment = h.next(); - * if(segment == null) - * { - * break; - * } - * Log.d(TAG,segment[0]); - * startPlayer(segment[0],segment[1]); - */ - Bundle params = new Bundle(); - params.putString("url", "/sdcard/a.ts"); + ((UpcApp)getApplication()).setHLS(h); Intent mIntent = new Intent(this, VideoActivity.class); - mIntent.putExtras(params); - startActivity(mIntent); - + if(((UpcApp)getApplication()).getHLS() != null) + { + startActivity(mIntent); + } + else + { + Toast.makeText(this, "HLS engine error", Toast.LENGTH_LONG).show(); + } } catch (ErrorException e){ Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 6d476eb..836757e 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -1,12 +1,13 @@ package com.upc.pbe.upcnews; -import java.util.ArrayList; +import java.io.File; +import java.util.ArrayList; 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; @@ -16,15 +17,28 @@ public class HLS { private int currentSegment; private boolean endReached; private String localFolder; - //private fileDownloader fd; + //private FileDownloader fd; private BandwidthMeasurer bm; - public HLS(ArrayList parsed, String localFolder){ + public HLS(ArrayList parsed, String localFolder) + { + /* + * CLEAN DIRECTORY + */ + File dir = new File(localFolder); + String[] files = dir.list(); + for(int i = 0; i < files.length; i++) + { + File deleteme = new File(dir,files[i]); + Log.d(TAG,"Deleted " + files[i].toString()); + deleteme.delete(); + } currentVideo = currentQuality = currentSegment = 0; this.videos = parsed; endReached = false; this.localFolder = localFolder; bm = new BandwidthMeasurer(); + //fd = new FileDownloader(); } public void loadVideo() @@ -37,7 +51,7 @@ public class HLS { } } - public String[] next() + public String next() { Segment seg = segments.get(currentSegment++); Log.d(TAG, seg.getName() + " " + seg.getURL()); @@ -49,9 +63,6 @@ public class HLS { { currentQuality++; } - String[] data = new String[2]; - data[0] = seg.getURL().substring(seg.getURL().lastIndexOf("/")+2, seg.getURL().length()); - data[1] = seg.getName(); if(currentSegment == segments.size()) { if(endReached) @@ -60,6 +71,7 @@ public class HLS { } loadVideo(); } - return data; + + return localFolder + seg.getURL().substring(seg.getURL().lastIndexOf("/")+1, seg.getURL().length()); } } \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/UpcApp.java b/src/com/upc/pbe/upcnews/UpcApp.java index 719e874..e2f7c23 100644 --- a/src/com/upc/pbe/upcnews/UpcApp.java +++ b/src/com/upc/pbe/upcnews/UpcApp.java @@ -15,11 +15,22 @@ public class UpcApp extends Application implements OnSharedPreferenceChangeListe private String url = null; private String desc; private final static String localPath = Environment.getExternalStorageDirectory().getPath() + "/UPC NEWS/"; + private HLS h; public String getLocalPath(){ return localPath; } + public HLS getHLS() + { + return h; + } + + public void setHLS(HLS h) + { + this.h = h; + } + public String getUrl() { url = "http://" + prefs.getString("server", getString(R.string.defaultURL)); return url; diff --git a/src/com/upc/pbe/upcnews/VideoActivity.java b/src/com/upc/pbe/upcnews/VideoActivity.java index 91c394e..9351231 100644 --- a/src/com/upc/pbe/upcnews/VideoActivity.java +++ b/src/com/upc/pbe/upcnews/VideoActivity.java @@ -1,34 +1,58 @@ package com.upc.pbe.upcnews; import android.app.Activity; +import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.widget.MediaController; import android.widget.VideoView; -public class VideoActivity extends Activity { - - VideoView video; - String url; - +public class VideoActivity extends Activity +{ + private VideoView video; + private HLS h; + private final static String TAG = "VideoActivity"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); video = (VideoView) findViewById(R.id.videoView1); - url = this.getIntent().getExtras().getString("url"); - play(); + video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() + { + public void onCompletion(MediaPlayer mp) + { + play(null); + //playNext(); + } + }); + h = ((UpcApp)getApplication()).getHLS(); + h.loadVideo(); + playNext(); } - public void play() + public void play(String url) { + if(url == null) + { + super.finish(); + return; + } video.setVideoURI(Uri.parse(url)); video.setMediaController(new MediaController(this)); video.start(); video.requestFocus(); } + + public void playNext() + { + String next = h.next(); + Log.d(TAG,next); + //play(next); + play("/sdcard/a.ts"); + } @Override public boolean onCreateOptionsMenu(Menu menu) { -- libgit2 0.22.2