Java Code Examples for com.google.android.media.tv.companionlibrary.model.InternalProviderData#setAds()
The following examples show how to use
com.google.android.media.tv.companionlibrary.model.InternalProviderData#setAds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EpgSyncWithAdsJobService.java From xipl with Apache License 2.0 | 6 votes |
/** * Shift advertisement time to match program playback time. For channels with repeated program, * the time for current program may vary from what it was defined previously. * * @param oldProgramStartTimeMs Outdated program start time. * @param newProgramStartTimeMs Updated program start time. */ private static void shiftAdsTimeWithProgram( InternalProviderData internalProviderData, long oldProgramStartTimeMs, long newProgramStartTimeMs) { if (internalProviderData == null) { return; } long timeShift = newProgramStartTimeMs - oldProgramStartTimeMs; List<Advertisement> oldAds = internalProviderData.getAds(); List<Advertisement> newAds = new ArrayList<>(); for (Advertisement oldAd : oldAds) { newAds.add( new Advertisement.Builder(oldAd) .setStartTimeUtcMillis(oldAd.getStartTimeUtcMillis() + timeShift) .setStopTimeUtcMillis(oldAd.getStopTimeUtcMillis() + timeShift) .build()); } internalProviderData.setAds(newAds); }
Example 2
Source File: EpgSyncJobService.java From xipl with Apache License 2.0 | 6 votes |
/** * Shift advertisement time to match program playback time. For channels with repeated program, * the time for current program may vary from what it was defined previously. * * @param oldProgramStartTimeMs Outdated program start time. * @param newProgramStartTimeMs Updated program start time. */ private void shiftAdsTimeWithProgram(InternalProviderData internalProviderData, long oldProgramStartTimeMs, long newProgramStartTimeMs) { if (internalProviderData == null) { return; } long timeShift = newProgramStartTimeMs - oldProgramStartTimeMs; List<Advertisement> oldAds = internalProviderData.getAds(); List<Advertisement> newAds = new ArrayList<>(); for (Advertisement oldAd : oldAds) { newAds.add(new Advertisement.Builder(oldAd) .setStartTimeUtcMillis(oldAd.getStartTimeUtcMillis() + timeShift) .setStopTimeUtcMillis(oldAd.getStopTimeUtcMillis() + timeShift) .build()); } internalProviderData.setAds(newAds); }
Example 3
Source File: EpgSyncWithAdsJobService.java From androidtv-sample-inputs with Apache License 2.0 | 6 votes |
/** * Shift advertisement time to match program playback time. For channels with repeated program, * the time for current program may vary from what it was defined previously. * * @param oldProgramStartTimeMs Outdated program start time. * @param newProgramStartTimeMs Updated program start time. */ private static void shiftAdsTimeWithProgram( InternalProviderData internalProviderData, long oldProgramStartTimeMs, long newProgramStartTimeMs) { if (internalProviderData == null) { return; } long timeShift = newProgramStartTimeMs - oldProgramStartTimeMs; List<Advertisement> oldAds = internalProviderData.getAds(); List<Advertisement> newAds = new ArrayList<>(); for (Advertisement oldAd : oldAds) { newAds.add( new Advertisement.Builder(oldAd) .setStartTimeUtcMillis(oldAd.getStartTimeUtcMillis() + timeShift) .setStopTimeUtcMillis(oldAd.getStopTimeUtcMillis() + timeShift) .build()); } internalProviderData.setAds(newAds); }
Example 4
Source File: SampleJobService.java From androidtv-sample-inputs with Apache License 2.0 | 5 votes |
@Override public List<Channel> getChannels() { // Add channels through an XMLTV file XmlTvParser.TvListing listings = RichFeedUtil.getRichTvListings(this); List<Channel> channelList = new ArrayList<>(listings.getChannels()); // Build advertisement list for the channel. Advertisement channelAd = new Advertisement.Builder() .setType(Advertisement.TYPE_VAST) .setRequestUrl(TEST_AD_REQUEST_URL) .build(); List<Advertisement> channelAdList = new ArrayList<>(); channelAdList.add(channelAd); // Add a channel programmatically InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(true); internalProviderData.setAds(channelAdList); Channel channelTears = new Channel.Builder() .setDisplayName(MPEG_DASH_CHANNEL_NAME) .setDisplayNumber(MPEG_DASH_CHANNEL_NUMBER) .setChannelLogo(MPEG_DASH_CHANNEL_LOGO) .setOriginalNetworkId(MPEG_DASH_ORIGINAL_NETWORK_ID) .setInternalProviderData(internalProviderData) .build(); channelList.add(channelTears); return channelList; }
Example 5
Source File: XmlTvParser.java From xipl with Apache License 2.0 | 4 votes |
private static Channel parseChannel(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String id = null; boolean repeatPrograms = false; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_ID.equalsIgnoreCase(attr)) { id = value; } else if (ATTR_REPEAT_PROGRAMS.equalsIgnoreCase(attr)) { repeatPrograms = "TRUE".equalsIgnoreCase(value); } } String displayName = null; String displayNumber = null; XmlTvIcon icon = null; XmlTvAppLink appLink = null; Advertisement advertisement = null; while (parser.next() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_DISPLAY_NAME.equalsIgnoreCase(parser.getName()) && displayName == null) { displayName = parser.nextText(); } else if (TAG_DISPLAY_NUMBER.equalsIgnoreCase(parser.getName()) && displayNumber == null) { displayNumber = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) { icon = parseIcon(parser); } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName()) && appLink == null) { appLink = parseAppLink(parser); } else if (TAG_AD.equalsIgnoreCase(parser.getName()) && advertisement == null) { advertisement = parseAd(parser, TAG_CHANNEL); } } else if (TAG_CHANNEL.equalsIgnoreCase(parser.getName()) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(id) || TextUtils.isEmpty(displayName)) { // In this case, the channel is simply invalid so skip it... return null; } // Developers should assign original network ID in the right way not using the fake ID. InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(repeatPrograms); Channel.Builder builder = new Channel.Builder() .setDisplayName(displayName) .setDisplayNumber(displayNumber) .setOriginalNetworkId(id.hashCode()) .setInternalProviderData(internalProviderData) .setTransportStreamId(0) .setServiceId(0); if (icon != null) { builder.setChannelLogo(icon.src); } if (appLink != null) { builder.setAppLinkColor(appLink.color) .setAppLinkIconUri(appLink.icon.src) .setAppLinkIntentUri(appLink.intentUri) .setAppLinkPosterArtUri(appLink.posterUri) .setAppLinkText(appLink.text); } if (advertisement != null) { List<Advertisement> advertisements = new ArrayList<>(1); advertisements.add(advertisement); internalProviderData.setAds(advertisements); builder.setInternalProviderData(internalProviderData); } return builder.build(); }
Example 6
Source File: XmlTvParser.java From xipl with Apache License 2.0 | 4 votes |
private static Program parseProgram(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String channelId = null; Long startTimeUtcMillis = null; Long endTimeUtcMillis = null; String videoSrc = null; int videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_CHANNEL.equalsIgnoreCase(attr)) { channelId = value; } else if (ATTR_START.equalsIgnoreCase(attr)) { startTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_STOP.equalsIgnoreCase(attr)) { endTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_VIDEO_SRC.equalsIgnoreCase(attr)) { videoSrc = value; } else if (ATTR_VIDEO_TYPE.equalsIgnoreCase(attr)) { if (VALUE_VIDEO_TYPE_HTTP_PROGRESSIVE.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; } else if (VALUE_VIDEO_TYPE_HLS.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HLS; } else if (VALUE_VIDEO_TYPE_MPEG_DASH.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_MPEG_DASH; } } } String title = null; String description = null; XmlTvIcon icon = null; List<String> category = new ArrayList<>(); List<TvContentRating> rating = new ArrayList<>(); List<Advertisement> ads = new ArrayList<>(); while (parser.next() != XmlPullParser.END_DOCUMENT) { String tagName = parser.getName(); if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_TITLE.equalsIgnoreCase(parser.getName())) { title = parser.nextText(); } else if (TAG_DESC.equalsIgnoreCase(tagName)) { description = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(tagName)) { icon = parseIcon(parser); } else if (TAG_CATEGORY.equalsIgnoreCase(tagName)) { category.add(parser.nextText()); } else if (TAG_RATING.equalsIgnoreCase(tagName)) { TvContentRating xmlTvRating = xmlTvRatingToTvContentRating(parseRating(parser)); if (xmlTvRating != null) { rating.add(xmlTvRating); } } else if (TAG_AD.equalsIgnoreCase(tagName)) { ads.add(parseAd(parser, TAG_PROGRAM)); } } else if (TAG_PROGRAM.equalsIgnoreCase(tagName) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(channelId) || startTimeUtcMillis == null || endTimeUtcMillis == null) { throw new IllegalArgumentException("channel, start, and end can not be null."); } InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setVideoType(videoType); internalProviderData.setVideoUrl(videoSrc); internalProviderData.setAds(ads); 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); } }
Example 7
Source File: CumulusXmlParser.java From CumulusTV with MIT License | 4 votes |
private static Channel parseChannel(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String id = null; boolean repeatPrograms = false; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_ID.equalsIgnoreCase(attr)) { id = value; } else if (ATTR_REPEAT_PROGRAMS.equalsIgnoreCase(attr)) { repeatPrograms = "TRUE".equalsIgnoreCase(value); } } String displayName = null; String displayNumber = null; XmlTvIcon icon = null; XmlTvAppLink appLink = null; Advertisement advertisement = null; while (parser.next() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_DISPLAY_NAME.equalsIgnoreCase(parser.getName()) && displayName == null) { displayName = parser.nextText(); } else if (TAG_DISPLAY_NUMBER.equalsIgnoreCase(parser.getName()) && displayNumber == null) { displayNumber = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) { icon = parseIcon(parser); } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName()) && appLink == null) { appLink = parseAppLink(parser); } else if (TAG_AD.equalsIgnoreCase(parser.getName()) && advertisement == null) { advertisement = parseAd(parser, TAG_CHANNEL); } } else if (TAG_CHANNEL.equalsIgnoreCase(parser.getName()) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(id) || TextUtils.isEmpty(displayName)) { throw new IllegalArgumentException("id and display-name can not be null."); } // Developers should assign original network ID in the right way not using the fake ID. InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(repeatPrograms); Channel.Builder builder = new Channel.Builder() .setDisplayName(displayName) .setDisplayNumber(displayNumber) .setOriginalNetworkId(id.hashCode()) .setInternalProviderData(internalProviderData) .setTransportStreamId(0) .setServiceId(0); if (icon != null) { builder.setChannelLogo(icon.src); } if (appLink != null) { builder.setAppLinkColor(appLink.color) .setAppLinkIconUri(appLink.icon.src) .setAppLinkIntentUri(appLink.intentUri) .setAppLinkPosterArtUri(appLink.posterUri) .setAppLinkText(appLink.text); } if (advertisement != null) { List<Advertisement> advertisements = new ArrayList<>(1); advertisements.add(advertisement); internalProviderData.setAds(advertisements); builder.setInternalProviderData(internalProviderData); } return builder.build(); }
Example 8
Source File: CumulusXmlParser.java From CumulusTV with MIT License | 4 votes |
private static Program parseProgram(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String channelId = null; Long startTimeUtcMillis = null; Long endTimeUtcMillis = null; String videoSrc = null; int videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_CHANNEL.equalsIgnoreCase(attr)) { channelId = value; } else if (ATTR_START.equalsIgnoreCase(attr)) { startTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_STOP.equalsIgnoreCase(attr)) { endTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_VIDEO_SRC.equalsIgnoreCase(attr)) { videoSrc = value; } else if (ATTR_VIDEO_TYPE.equalsIgnoreCase(attr)) { if (VALUE_VIDEO_TYPE_HTTP_PROGRESSIVE.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; } else if (VALUE_VIDEO_TYPE_HLS.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HLS; } else if (VALUE_VIDEO_TYPE_MPEG_DASH.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_MPEG_DASH; } } } String title = null; String description = null; XmlTvIcon icon = null; List<String> category = new ArrayList<>(); List<TvContentRating> rating = new ArrayList<>(); List<Advertisement> ads = new ArrayList<>(); while (parser.next() != XmlPullParser.END_DOCUMENT) { String tagName = parser.getName(); if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_TITLE.equalsIgnoreCase(parser.getName())) { title = parser.nextText(); } else if (TAG_DESC.equalsIgnoreCase(tagName)) { description = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(tagName)) { icon = parseIcon(parser); } else if (TAG_CATEGORY.equalsIgnoreCase(tagName)) { category.add(parser.nextText()); } else if (TAG_RATING.equalsIgnoreCase(tagName)) { TvContentRating xmlTvRating = xmlTvRatingToTvContentRating(parseRating(parser)); if (xmlTvRating != null) rating.add(xmlTvRating); } else if (TAG_AD.equalsIgnoreCase(tagName)) { ads.add(parseAd(parser, TAG_PROGRAM)); } } else if (TAG_PROGRAM.equalsIgnoreCase(tagName) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(channelId) || startTimeUtcMillis == null || endTimeUtcMillis == null) { throw new IllegalArgumentException("channel, start, and end can not be null."); } InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setVideoType(videoType); internalProviderData.setVideoUrl(videoSrc); internalProviderData.setAds(ads); 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(); }
Example 9
Source File: SampleJobService.java From androidtv-sample-inputs with Apache License 2.0 | 4 votes |
@Override public List<Program> getOriginalProgramsForChannel(Uri channelUri, Channel channel, long startMs, long endMs) { if (!channel.getDisplayName().equals(MPEG_DASH_CHANNEL_NAME)) { // Is an XMLTV Channel XmlTvParser.TvListing listings = RichFeedUtil.getRichTvListings(getApplicationContext()); return listings.getPrograms(channel); } else { // Build Advertisement list for the program. Advertisement programAd1 = new Advertisement.Builder() .setStartTimeUtcMillis(TEST_AD_1_START_TIME_MS) .setStopTimeUtcMillis(TEST_AD_1_START_TIME_MS + TEST_AD_DURATION_MS) .setType(Advertisement.TYPE_VAST) .setRequestUrl(TEST_AD_REQUEST_URL) .build(); Advertisement programAd2 = new Advertisement.Builder(programAd1) .setStartTimeUtcMillis(TEST_AD_2_START_TIME_MS) .setStopTimeUtcMillis(TEST_AD_2_START_TIME_MS + TEST_AD_DURATION_MS) .build(); List<Advertisement> programAdList = new ArrayList<>(); programAdList.add(programAd1); programAdList.add(programAd2); // Programatically add channel List<Program> programsTears = new ArrayList<>(); InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setVideoType(Util.TYPE_DASH); internalProviderData.setVideoUrl(TEARS_OF_STEEL_SOURCE); internalProviderData.setAds(programAdList); programsTears.add(new Program.Builder() .setTitle(TEARS_OF_STEEL_TITLE) .setStartTimeUtcMillis(TEARS_OF_STEEL_START_TIME_MS) .setEndTimeUtcMillis(TEARS_OF_STEEL_START_TIME_MS + TEARS_OF_STEEL_DURATION_MS) .setDescription(TEARS_OF_STEEL_DESCRIPTION) .setCanonicalGenres(new String[] {TvContract.Programs.Genres.TECH_SCIENCE, TvContract.Programs.Genres.MOVIES}) .setPosterArtUri(TEARS_OF_STEEL_ART) .setThumbnailUri(TEARS_OF_STEEL_ART) .setInternalProviderData(internalProviderData) .build()); return programsTears; } }
Example 10
Source File: XmlTvParser.java From androidtv-sample-inputs with Apache License 2.0 | 4 votes |
private static Channel parseChannel(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String id = null; boolean repeatPrograms = false; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_ID.equalsIgnoreCase(attr)) { id = value; } else if (ATTR_REPEAT_PROGRAMS.equalsIgnoreCase(attr)) { repeatPrograms = "TRUE".equalsIgnoreCase(value); } } String displayName = null; String displayNumber = null; XmlTvIcon icon = null; XmlTvAppLink appLink = null; Advertisement advertisement = null; while (parser.next() != XmlPullParser.END_DOCUMENT) { if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_DISPLAY_NAME.equalsIgnoreCase(parser.getName()) && displayName == null) { displayName = parser.nextText(); } else if (TAG_DISPLAY_NUMBER.equalsIgnoreCase(parser.getName()) && displayNumber == null) { displayNumber = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(parser.getName()) && icon == null) { icon = parseIcon(parser); } else if (TAG_APP_LINK.equalsIgnoreCase(parser.getName()) && appLink == null) { appLink = parseAppLink(parser); } else if (TAG_AD.equalsIgnoreCase(parser.getName()) && advertisement == null) { advertisement = parseAd(parser, TAG_CHANNEL); } } else if (TAG_CHANNEL.equalsIgnoreCase(parser.getName()) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(id) || TextUtils.isEmpty(displayName)) { throw new IllegalArgumentException("id and display-name can not be null."); } // Developers should assign original network ID in the right way not using the fake ID. InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(repeatPrograms); Channel.Builder builder = new Channel.Builder() .setDisplayName(displayName) .setDisplayNumber(displayNumber) .setOriginalNetworkId(id.hashCode()) .setInternalProviderData(internalProviderData) .setTransportStreamId(0) .setServiceId(0); if (icon != null) { builder.setChannelLogo(icon.src); } if (appLink != null) { builder.setAppLinkColor(appLink.color) .setAppLinkIconUri(appLink.icon.src) .setAppLinkIntentUri(appLink.intentUri) .setAppLinkPosterArtUri(appLink.posterUri) .setAppLinkText(appLink.text); } if (advertisement != null) { List<Advertisement> advertisements = new ArrayList<>(1); advertisements.add(advertisement); internalProviderData.setAds(advertisements); builder.setInternalProviderData(internalProviderData); } return builder.build(); }
Example 11
Source File: XmlTvParser.java From androidtv-sample-inputs with Apache License 2.0 | 4 votes |
private static Program parseProgram(XmlPullParser parser) throws IOException, XmlPullParserException, ParseException { String channelId = null; Long startTimeUtcMillis = null; Long endTimeUtcMillis = null; String videoSrc = null; int videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; for (int i = 0; i < parser.getAttributeCount(); ++i) { String attr = parser.getAttributeName(i); String value = parser.getAttributeValue(i); if (ATTR_CHANNEL.equalsIgnoreCase(attr)) { channelId = value; } else if (ATTR_START.equalsIgnoreCase(attr)) { startTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_STOP.equalsIgnoreCase(attr)) { endTimeUtcMillis = DATE_FORMAT.parse(value).getTime(); } else if (ATTR_VIDEO_SRC.equalsIgnoreCase(attr)) { videoSrc = value; } else if (ATTR_VIDEO_TYPE.equalsIgnoreCase(attr)) { if (VALUE_VIDEO_TYPE_HTTP_PROGRESSIVE.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE; } else if (VALUE_VIDEO_TYPE_HLS.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_HLS; } else if (VALUE_VIDEO_TYPE_MPEG_DASH.equals(value)) { videoType = TvContractUtils.SOURCE_TYPE_MPEG_DASH; } } } String title = null; String description = null; XmlTvIcon icon = null; List<String> category = new ArrayList<>(); List<TvContentRating> rating = new ArrayList<>(); List<Advertisement> ads = new ArrayList<>(); while (parser.next() != XmlPullParser.END_DOCUMENT) { String tagName = parser.getName(); if (parser.getEventType() == XmlPullParser.START_TAG) { if (TAG_TITLE.equalsIgnoreCase(parser.getName())) { title = parser.nextText(); } else if (TAG_DESC.equalsIgnoreCase(tagName)) { description = parser.nextText(); } else if (TAG_ICON.equalsIgnoreCase(tagName)) { icon = parseIcon(parser); } else if (TAG_CATEGORY.equalsIgnoreCase(tagName)) { category.add(parser.nextText()); } else if (TAG_RATING.equalsIgnoreCase(tagName)) { TvContentRating xmlTvRating = xmlTvRatingToTvContentRating(parseRating(parser)); if (xmlTvRating != null) { rating.add(xmlTvRating); } } else if (TAG_AD.equalsIgnoreCase(tagName)) { ads.add(parseAd(parser, TAG_PROGRAM)); } } else if (TAG_PROGRAM.equalsIgnoreCase(tagName) && parser.getEventType() == XmlPullParser.END_TAG) { break; } } if (TextUtils.isEmpty(channelId) || startTimeUtcMillis == null || endTimeUtcMillis == null) { throw new IllegalArgumentException("channel, start, and end can not be null."); } InternalProviderData internalProviderData = new InternalProviderData(); 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(); }