VideoActivity.java
2.91 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.upc.pbe.upcnews;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import java.io.IOException;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
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 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
//Creem el layout
super.onCreate(savedInstanceState);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
{
return;
}
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)
io.vov.vitamio.widget.MediaController mc = new MediaController(this);
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
//Al acabar cada ts, reproduit el seguent
playNext();
}
});
mc.setOnFFLeftListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d(TAG, "FFLEFT");
video.stopPlayback();
playPrevious();
}
});
mc.setOnFFRightListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d(TAG, "FFRIGHT");
video.stopPlayback();
playNext();
}
});
video.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
//Creem un gestor HLS, carreguem el video i iniciem la reproduccio
h = ((UpcApp)getApplication()).getHLS();
h.setDefQuality(((UpcApp)getApplication()).getQuality());
h.loadVideo();
video.stopPlayback();
video.setMediaController(mc);
playNext();
}
public void play(String url) {
if(url == null) {
super.finish();
return;
}
Log.d(TAG,"A reproduir: " + url);
video.setVideoPath("file://" + url);
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;
}
}
public void playPrevious() {
try {
String prev = h.previous();
play(prev);
}
catch(IOException e) {
Toast.makeText(this, "No s'ha trobat el segment", Toast.LENGTH_LONG).show();
super.finish();
return;
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (video != null)
video.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
super.onConfigurationChanged(newConfig);
}
// Que coño es esto gueyes???
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Determina el funcionament al apretar la tecla d'opcions
getMenuInflater().inflate(R.menu.activity_video, menu);
return true;
}*/
}