Java Code Examples for com.google.android.media.tv.companionlibrary.model.InternalProviderData#setVideoUrl()
The following examples show how to use
com.google.android.media.tv.companionlibrary.model.InternalProviderData#setVideoUrl() .
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: XmlTvParserTest.java From xipl with Apache License 2.0 | 5 votes |
@Test public void testProgramParsing() throws XmlTvParser.XmlTvParseException { String testXmlFile = "xmltv.xml"; String APRIL_FOOLS_SOURCE = "https://commondatastorage.googleapis.com/android-tv/Sample%2" + "0videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4"; String ELEPHANTS_DREAM_POSTER_ART = "https://storage.googleapis.com/gtv-videos-bucket/sam" + "ple/images_480x270/ElephantsDream.jpg"; InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile); XmlTvParser.TvListing listings = XmlTvParser.parse(inputStream); assertEquals(9, listings.getAllPrograms().size()); assertEquals("Introducing Gmail Blue", listings.getAllPrograms().get(0).getTitle()); assertEquals("Introducing Gmail Blue", listings.getPrograms(listings.getChannels().get(0)).get(0).getTitle()); assertEquals(TvContract.Programs.Genres.TECH_SCIENCE, listings.getAllPrograms().get(1).getCanonicalGenres()[1]); assertEquals(listings.getAllPrograms().get(2).getChannelId(), listings.getChannels().get(0).getOriginalNetworkId()); assertNotNull(listings.getAllPrograms().get(3).getInternalProviderData()); assertEquals(APRIL_FOOLS_SOURCE, listings.getAllPrograms().get(3).getInternalProviderData().getVideoUrl()); assertEquals("Introducing Google Nose", listings.getAllPrograms().get(4).getDescription()); assertEquals(ELEPHANTS_DREAM_POSTER_ART, listings.getAllPrograms().get(5).getPosterArtUri()); InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setVideoType(TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE); internalProviderData.setVideoUrl(APRIL_FOOLS_SOURCE); assertEquals(internalProviderData, listings.getAllPrograms().get(3).getInternalProviderData()); }
Example 2
Source File: ProviderChannelUtil.java From xipl with Apache License 2.0 | 5 votes |
/** * Creates a {@link Channel} that can be used by the Android TV framework and the Live Channels application. * * @param displayName the display name of the channel * @param displayNumber the display number of the channel * @param epgId the id as defined in {@link com.google.android.media.tv.companionlibrary.xmltv.XmlTvParser} * @param logo the logo url link * @param url the video url link * @return the channel to be used by the system. */ private static Channel createChannel(String displayName, String displayNumber, int epgId, String logo, String url, String group, String[] genres) { /* In order to map correctly the programs to a given channel, store the EPG id somewhere in the channel so we can retrieve it when we'll need to find programs Using the EPG ID as a good way to have an original network id but it might create channel duplicates. Since some channels either don't have an EPG id (which makes 0 as a hash) or might share the same id altogether, (same channel in SD/HD for example) they get recreated as their original id isn't really original anymore... In that case, let's use the display name as the original network id instead of the EPG id. Let's also retrieve the an example genre for the channel so it can be passed on the side of the EPG guide. */ Channel.Builder builder = new Channel.Builder(); InternalProviderData internalProviderData = new InternalProviderData(); try { JSONArray genresJsonArray = new JSONArray(genres); internalProviderData.put(Constants.EPG_ID_PROVIDER, epgId); internalProviderData.put(Constants.CHANNEL_GENRES_PROVIDER, genresJsonArray); } catch (InternalProviderData.ParseException ps) { // Can't do anything about this... } catch (JSONException json) { json.printStackTrace(); } internalProviderData.setVideoUrl(url); builder.setDisplayName(displayName); builder.setDisplayNumber(displayNumber); builder.setOriginalNetworkId(displayName.hashCode()); builder.setChannelLogo(logo); builder.setNetworkAffiliation(group); builder.setInternalProviderData(internalProviderData); return (builder.build()); }
Example 3
Source File: JsonChannel.java From CumulusTV with MIT License | 5 votes |
public Channel toChannel() { InternalProviderData ipd = new InternalProviderData(); ipd.setVideoUrl(getMediaUrl()); ipd.setVideoType(TvContractUtils.SOURCE_TYPE_HLS); return new Channel.Builder() .setDisplayName(getName()) .setDisplayNumber(getNumber()) .setChannelLogo(getLogo()) .setInternalProviderData(ipd) .setOriginalNetworkId(getMediaUrl().hashCode()) .build(); }
Example 4
Source File: JsonChannel.java From CumulusTV with MIT License | 5 votes |
public Channel toChannel(InternalProviderData providerData) { providerData.setVideoUrl(getMediaUrl()); // TODO Add app linking return new Channel.Builder() .setDisplayName(getName()) .setDisplayNumber(getNumber()) .setChannelLogo(getLogo()) .setInternalProviderData(providerData) .setOriginalNetworkId(getMediaUrl().hashCode()) .build(); }
Example 5
Source File: XmlTvParserTest.java From androidtv-sample-inputs with Apache License 2.0 | 5 votes |
@Test public void testProgramParsing() throws XmlTvParser.XmlTvParseException { String testXmlFile = "xmltv.xml"; String APRIL_FOOLS_SOURCE = "https://commondatastorage.googleapis.com/android-tv/Sample%2" + "0videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4"; String ELEPHANTS_DREAM_POSTER_ART = "https://storage.googleapis.com/gtv-videos-bucket/sam" + "ple/images_480x270/ElephantsDream.jpg"; InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile); XmlTvParser.TvListing listings = XmlTvParser.parse(inputStream); assertEquals(9, listings.getAllPrograms().size()); assertEquals("Introducing Gmail Blue", listings.getAllPrograms().get(0).getTitle()); assertEquals("Introducing Gmail Blue", listings.getPrograms(listings.getChannels().get(0)).get(0).getTitle()); assertEquals(TvContract.Programs.Genres.TECH_SCIENCE, listings.getAllPrograms().get(1).getCanonicalGenres()[1]); assertEquals(listings.getAllPrograms().get(2).getChannelId(), listings.getChannels().get(0).getOriginalNetworkId()); assertNotNull(listings.getAllPrograms().get(3).getInternalProviderData()); assertEquals(APRIL_FOOLS_SOURCE, listings.getAllPrograms().get(3).getInternalProviderData().getVideoUrl()); assertEquals("Introducing Google Nose", listings.getAllPrograms().get(4).getDescription()); assertEquals(ELEPHANTS_DREAM_POSTER_ART, listings.getAllPrograms().get(5).getPosterArtUri()); InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setVideoType(TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE); internalProviderData.setVideoUrl(APRIL_FOOLS_SOURCE); assertEquals(internalProviderData, listings.getAllPrograms().get(3).getInternalProviderData()); }
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 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 8
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 9
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(); }