VideoActivity.java
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.upc.pbe.upcnews;
import java.io.IOException;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import io.vov.vitamio.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import io.vov.vitamio.widget.MediaController;
import android.widget.Toast;
//Tercera activitat principal, executa la reproduccio del video sencer
public class VideoActivity extends Activity {
private final static String TAG = "VideoActivity";
private VideoView video;
private HLS h;
@Override
public void onCreate(Bundle savedInstanceState) {
//Creem el layout
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
video = (VideoView) findViewById(R.id.videoView1);
//Creem un listener associat al fi de l'activitat (el fi de cada ts)
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//Al acabar cada ts, reproduit el seguent
playNext();
}
});
//Creem un gestor HLS, carreguem el video i iniciem la reproduccio
h = ((UpcApp)getApplication()).getHLS();
h.setDefQuality(((UpcApp)getApplication()).getQuality());
h.loadVideo();
playNext();
}
public void play(String url) {
if(url == null) {
super.finish();
return;
}
Log.d(TAG,url);
video.setVideoURI(Uri.parse(url));
video.setMediaController(new MediaController(this));
video.start();
video.requestFocus();
}
public void playNext() {
try {
String next = h.next();
play(next);
}
catch(IOException e) {
Toast.makeText(this, "No s'ha trobat el segment", Toast.LENGTH_LONG).show();
super.finish();
return;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Determina el funcionament al apretar la tecla d'opcions
getMenuInflater().inflate(R.menu.activity_video, menu);
return true;
}
}