Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -399,27 +399,30 @@ public Void doInBackground(Void... voids) {
}
List<Program> programs = getProgramsForChannel(channelUri, channelMap.valueAt(i),
startMs, endMs);
if (DEBUG) {
Log.d(TAG, programs.toString());
}
for (int index = 0; index < programs.size(); index++) {
if (programs.get(index).getChannelId() == -1) {
// Automatically set the channel id if not set
programs.set(index,
new Program.Builder(programs.get(index))
.setChannelId(channelMap.valueAt(i).getId())
.build());

if (programs != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be cases when the program list will be null while using the library?

Copy link
Author

@zaclimon zaclimon Jun 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case, the provider doesn't have all programs for a given channel in the EPG's XMLTV. Surely enough, I could simply pass an empty list instead of returning null on when getProgramsForChannel() is called.

if (DEBUG) {
Log.d(TAG, programs.toString());
}
for (int index = 0; index < programs.size(); index++) {
if (programs.get(index).getChannelId() == -1) {
// Automatically set the channel id if not set
programs.set(index,
new Program.Builder(programs.get(index))
.setChannelId(channelMap.valueAt(i).getId())
.build());
}
}
}

// Double check if the job is cancelled, so that this task can be finished faster
// after cancel() is called.
if (isCancelled()) {
broadcastError(ERROR_EPG_SYNC_CANCELED);
return null;
// Double check if the job is cancelled, so that this task can be finished faster
// after cancel() is called.
if (isCancelled()) {
broadcastError(ERROR_EPG_SYNC_CANCELED);
return null;
}
updatePrograms(channelUri,
getPrograms(channelMap.valueAt(i), programs, startMs, endMs));
}
updatePrograms(channelUri,
getPrograms(channelMap.valueAt(i), programs, startMs, endMs));
Intent intent = new Intent(ACTION_SYNC_STATUS_CHANGED);
intent.putExtra(EpgSyncJobService.BUNDLE_KEY_INPUT_ID, mInputId);
intent.putExtra(EpgSyncJobService.BUNDLE_KEY_CHANNELS_SCANNED, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ private static TvListing parseTvListings(XmlPullParser parser)
}
if (parser.getEventType() == XmlPullParser.START_TAG
&& TAG_PROGRAM.equalsIgnoreCase(parser.getName())) {
programs.add(parseProgram(parser));
Program program = parseProgram(parser);
if (program != null) {
programs.add(program);
}
}
}
return new TvListing(channels, programs);
Expand Down Expand Up @@ -340,21 +343,29 @@ private static Program parseProgram(XmlPullParser parser)
internalProviderData.setVideoType(videoType);
internalProviderData.setVideoUrl(videoSrc);
internalProviderData.setAds(ads);
return new Program.Builder()
.setChannelId(channelId.hashCode())
.setTitle(title)
.setDescription(description)
.setPosterArtUri(icon.src)
.setCanonicalGenres(category.toArray(new String[category.size()]))
.setStartTimeUtcMillis(startTimeUtcMillis)
.setEndTimeUtcMillis(endTimeUtcMillis)
.setContentRatings(rating.toArray(new TvContentRating[rating.size()]))
// NOTE: {@code COLUMN_INTERNAL_PROVIDER_DATA} is a private field
// where TvInputService can store anything it wants. Here, we store
// video type and video URL so that TvInputService can play the
// video later with this field.
.setInternalProviderData(internalProviderData)
.build();
try {
return new Program.Builder()
.setChannelId(channelId.hashCode())
.setTitle(title)
.setDescription(description)
.setPosterArtUri(icon != null ? icon.src : null)
.setCanonicalGenres(category.toArray(new String[category.size()]))
.setStartTimeUtcMillis(startTimeUtcMillis)
.setEndTimeUtcMillis(endTimeUtcMillis)
.setContentRatings(rating.toArray(new TvContentRating[rating.size()]))
// NOTE: {@code COLUMN_INTERNAL_PROVIDER_DATA} is a private field
// where TvInputService can store anything it wants. Here, we store
// video type and video URL so that TvInputService can play the
// video later with this field.
.setInternalProviderData(internalProviderData)
.build();
} catch (IllegalArgumentException e) {
// The program might not have valid start/end time.
// If that's the case, skip it...
Log.e(TAG, "Program not valid: Channel id: " + channelId.hashCode() + ", Title: " + title
+ ", Start time: " + startTimeUtcMillis + ", End time: " + endTimeUtcMillis);
return (null);
}
}

private static XmlTvIcon parseIcon(XmlPullParser parser)
Expand Down