Skip to content

Commit 7bd9c4d

Browse files
author
Ashfaq Ahmad
committed
bug fixes and improvements
1 parent b514757 commit 7bd9c4d

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

app/src/main/java/com/example/android/sampletvinput/parsers/MjunoonTvParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ private static String extractStreamUrl(String data) throws IOException
5151
for (String streamUrl : streamUrls) {
5252
String html_response = SimpleHttpClient.GET(streamUrl, Util.USER_AGENT_FIREFOX);
5353

54-
if(html_response.contains("#EXTM3U")) {
55-
return streamUrl;
54+
if(html_response != null && html_response.contains("#EXTM3U")) {
55+
return parseStreamUrl(streamUrl);
5656
}
5757
}
5858

5959
return null;
6060
}
6161

62-
/*
6362
private static String parseStreamUrl(String streamUrl) throws IOException {
6463
String html_response = SimpleHttpClient.GET(streamUrl, Util.USER_AGENT_FIREFOX);
6564

@@ -91,6 +90,4 @@ private static String parseStreamUrl(String streamUrl) throws IOException {
9190

9291
return null;
9392
}
94-
*/
95-
9693
}

app/src/main/java/com/example/android/sampletvinput/parsers/TvUrlParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ public static String parseVideoUrl(String videoUrl) {
1919

2020
for(String url : videoUrlArray) {
2121
returnUrl = null;
22+
boolean parserFound = false;
2223
for (VideoUrlParser videoUrlParser: videoUrlParserArray) {
2324
if(url.contains(videoUrlParser.getParserId())) {
25+
parserFound = true;
2426
returnUrl = videoUrlParser.parseVideoUrl(url);
2527
break;
2628
}
2729
}
2830

29-
if(returnUrl == null){
30-
returnUrl = url;
31+
if(parserFound == false) {
32+
returnUrl = videoUrl;
3133
}
34+
3235
if(SimpleHttpClient.isValidUrl(returnUrl, Util.USER_AGENT_FIREFOX)) {
3336
return returnUrl;
3437
}

app/src/main/java/com/example/android/sampletvinput/rich/RichTvInputService.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ public boolean onPlayProgram(Program program, long startPosMs) {
233233
if (startPosMs > 0) {
234234
mPlayer.seekTo(startPosMs);
235235
}
236-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
237-
notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
238-
}
236+
notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
239237
mPlayer.setPlayWhenReady(true);
240238
return true;
241239
}
@@ -248,9 +246,7 @@ public boolean onPlayRecordedProgram(RecordedProgram recordedProgram) {
248246
long recordingStartTime = recordedProgram.getInternalProviderData()
249247
.getRecordedProgramStartTime();
250248
mPlayer.seekTo(recordingStartTime - recordedProgram.getStartTimeUtcMillis());
251-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
252-
notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
253-
}
249+
notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
254250
mPlayer.setPlayWhenReady(true);
255251
return true;
256252
}

app/src/main/java/com/example/android/sampletvinput/util/SimpleHttpClient.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SimpleHttpClient
1919
private static String TAG = "SimpleHttpClient";
2020

2121
public static final String ENCODING_UTF_8 = "UTF-8";
22-
public static final int DEFAULT_TIMEOUT = 10000;
22+
public static final int DEFAULT_TIMEOUT = 3000;
2323

2424
public static final String HTTP_GET = "GET";
2525
public static final String HTTP_POST = "POST";
@@ -48,6 +48,10 @@ public static boolean isValidUrl(String urlStr, String userAgent) {
4848
URL url = null;
4949
HttpURLConnection urlConnection = null;
5050

51+
if(urlStr == null) {
52+
return false;
53+
}
54+
5155
try {
5256
url = new URL(urlStr);
5357
urlConnection = (HttpURLConnection) url.openConnection();
@@ -83,6 +87,10 @@ private static String execute(String urlStr,
8387
OutputStream outStream = null;
8488
String response = null;
8589

90+
if(urlStr == null) {
91+
return null;
92+
}
93+
8694
try
8795
{
8896
url = new URL(urlStr);
@@ -117,9 +125,10 @@ private static String execute(String urlStr,
117125
response="";
118126
}
119127
} catch (Exception e) {
120-
121-
inStream = new BufferedInputStream(urlConnection.getInputStream());
122-
response = getInput(inStream);
128+
if(urlConnection != null) {
129+
inStream = new BufferedInputStream(urlConnection.getInputStream());
130+
response = getInput(inStream);
131+
}
123132
}
124133
finally
125134
{

0 commit comments

Comments
 (0)