Directoris.java
4.05 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.upc.pbe.upcnews;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Directoris extends Activity implements OnClickListener {
final static String TAG = "Directoris";
String s;
Descarrega d;
String url;
ArrayList<Button> buttons = new ArrayList<Button>();
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreated");
url = ((UpcApp) getApplication()).getUrl();
super.onCreate(savedInstanceState);
setContentView(R.layout.dirs);
//Descarrega del HTML de l'index, busqueda de directoris i creacio dels botons
this.crearButtons();
s = ((UpcApp) getApplication()).getDesc();
HTMLParser pars = new HTMLParser();
ArrayList<String> dirs = pars.parse(s);
for (int i = 0; i < dirs.size(); i++) {
Log.d(TAG, "Directori " + dirs.get(i).toString());
buttons.get(i).setVisibility(View.VISIBLE);
buttons.get(i).setText(dirs.get(i));
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
Log.d(TAG, "Menu");
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.itemprefs:
startActivity(new Intent(this, Prefs.class));
Log.d(TAG, "Preferences");
return true;
case R.id.itemhelp:
startActivity(new Intent(this, Help.class));
Log.d(TAG, "Help");
return true;
default:
return false;
}
}
public void onClick(View c) {
switch (c.getId()) {
case R.id.button1: {
this.buttonClicked(buttons.get(0));
break;
}
case R.id.button2: {
this.buttonClicked(buttons.get(1));
break;
}
case R.id.button3: {
this.buttonClicked(buttons.get(2));
break;
}
case R.id.button4: {
this.buttonClicked(buttons.get(3));
break;
}
}
}
public void crearButtons() {
buttons.add((Button) findViewById(R.id.button1));
buttons.add((Button) findViewById(R.id.button2));
buttons.add((Button) findViewById(R.id.button3));
buttons.add((Button) findViewById(R.id.button4));
buttons.add((Button) findViewById(R.id.button5));
for (int i = 0; i < buttons.size(); i++) {
buttons.get(i).setOnClickListener(this);
buttons.get(i).setVisibility(View.GONE);
}
}
public void buttonClicked(Button b) {
//Descarrega de la p�gina HTML del directori i busqueda d'un .m3u8 en ella
Log.d(TAG, "Click on " + b.getText());
d = new Descarrega();
String str = d.doInBackground(url + "/" + b.getText() + "/");
HTMLParser pars = new HTMLParser();
String urlvideo = pars.findvideo(str, url + "/" + b.getText() + "/");
Log.d(TAG, urlvideo);
//Descarrega de l'arxiu .m3u8 (si existeix) i parseig
if (urlvideo.equalsIgnoreCase("No s'ha trobat")) {
Toast.makeText(this, "The directory " + b.getText() + " does not contain any '.m3u8' file", Toast.LENGTH_LONG).show();
} else {
d = new Descarrega();
String m3u8 = d.doInBackground(urlvideo);
Log.d(TAG, m3u8);
Parser p = new Parser(urlvideo.substring(0,urlvideo.lastIndexOf("/")+1),this);
try {
ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8);
Log.d(TAG, "parsed completed");
HLS h = new HLS(m3u8parsed);
h.start();
} catch (ErrorException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
} catch (WarningException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
} catch (InfoException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
}
}
//VideoPlayer
/*
String urlvid = null;
((UpcApp) getApplication()).setDesc(urlvid);
startActivity(new Intent(this, VideoActivity.class));*/
}
}