com.google.android.media.tv.companionlibrary.utils.TvContractUtils Java Examples

The following examples show how to use com.google.android.media.tv.companionlibrary.utils.TvContractUtils. 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 androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@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: InternalProviderData.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the video type of the program.
 *
 * @return The video type of the program, -1 if no value has been given.
 */
public int getVideoType() {
    if (mJsonObject.has(KEY_VIDEO_TYPE)) {
        try {
            return mJsonObject.getInt(KEY_VIDEO_TYPE);
        } catch (JSONException ignored) {
        }
    }
    return TvContractUtils.SOURCE_TYPE_INVALID;
}
 
Example #3
Source File: XmlTvParserTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: ProgramTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M) @Test
public void testFullyPopulatedProgram() {
    // Tests cloning and database I/O of a program with every value being defined.
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setVideoType(TvContractUtils.SOURCE_TYPE_HLS);
    internalProviderData.setVideoUrl("http://example.com/stream.m3u8");
    Program fullyPopulatedProgram = new Program.Builder()
            .setSearchable(false)
            .setChannelId(3)
            .setThumbnailUri("http://example.com/thumbnail.png")
            .setInternalProviderData(internalProviderData)
            .setAudioLanguages("en-us")
            .setBroadcastGenres(new String[] {"Music", "Family"})
            .setCanonicalGenres(new String[] {TvContract.Programs.Genres.MOVIES})
            .setContentRatings(new TvContentRating[] {TvContentRating.UNRATED})
            .setDescription("This is a sample program")
            .setEndTimeUtcMillis(1000)
            .setEpisodeNumber("Pilot", 0)
            .setEpisodeTitle("Hello World")
            .setLongDescription("This is a longer description than the previous description")
            .setPosterArtUri("http://example.com/poster.png")
            .setRecordingProhibited(false)
            .setSeasonNumber("The Final Season", 7)
            .setSeasonTitle("The Final Season")
            .setStartTimeUtcMillis(0)
            .setTitle("Google")
            .setVideoHeight(1080)
            .setVideoWidth(1920)
            .build();

    ContentValues contentValues = fullyPopulatedProgram.toContentValues();
    compareProgram(fullyPopulatedProgram, Program.fromCursor(getProgramCursor(contentValues)));

    Program clonedFullyPopulatedProgram = new Program.Builder(fullyPopulatedProgram).build();
    compareProgram(fullyPopulatedProgram, clonedFullyPopulatedProgram);
}
 
Example #5
Source File: InternalProviderData.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the video type of the program.
 *
 * @return The video type of the program, -1 if no value has been given.
 */
public int getVideoType() {
    if (mJsonObject.has(KEY_VIDEO_TYPE)) {
        try {
            return mJsonObject.getInt(KEY_VIDEO_TYPE);
        } catch (JSONException ignored) {
        }
    }
    return TvContractUtils.SOURCE_TYPE_INVALID;
}
 
Example #6
Source File: JsonChannel.java    From CumulusTV with MIT License 5 votes vote down vote up
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 #7
Source File: CumulusJobService.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
    public List<Channel> 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);

        InternalProviderData ipd = new InternalProviderData();
//        ipd.setAds(channelAdList);
        ipd.setRepeatable(true);
        ipd.setVideoType(TvContractUtils.SOURCE_TYPE_HLS);

        try {
            List<Channel> channels = ChannelDatabase.getInstance(this).getChannels(ipd);
            // Add app linking
            for (int i = 0; i < channels.size(); i++) {
                JsonChannel jsonChannel =
                        ChannelDatabase.getInstance(this).findChannelByMediaUrl(
                                channels.get(i).getInternalProviderData().getVideoUrl());
                Channel channel = new Channel.Builder(channels.get(i))
                    .setAppLinkText(getString(R.string.quick_settings))
                    .setAppLinkIconUri("https://github.com/Fleker/CumulusTV/blob/master/app/src/m" +
                        "ain/res/drawable-xhdpi/ic_play_action_normal.png?raw=true")
                    .setAppLinkPosterArtUri(channels.get(i).getChannelLogo())
                    .setAppLinkIntent(PlaybackQuickSettingsActivity.getIntent(this, jsonChannel))
                    .build();
                Log.d(TAG, "Adding channel " + channel.getDisplayName());
                channels.set(i, channel);
            }
            Log.d(TAG, "Returning with " + channels.size() + " channels");
            return channels;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.w(TAG, "No channels found");
        return null;
    }
 
Example #8
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 4 votes vote down vote up
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: ProgramTest.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M) @Test
public void testFullyPopulatedProgram() {
    // Tests cloning and database I/O of a program with every value being defined.
    InternalProviderData internalProviderData = new InternalProviderData();
    internalProviderData.setVideoType(TvContractUtils.SOURCE_TYPE_HLS);
    internalProviderData.setVideoUrl("http://example.com/stream.m3u8");
    Program fullyPopulatedProgram = new Program.Builder()
            .setSearchable(false)
            .setChannelId(3)
            .setThumbnailUri("http://example.com/thumbnail.png")
            .setInternalProviderData(internalProviderData)
            .setAudioLanguages("en-us")
            .setBroadcastGenres(new String[] {"Music", "Family"})
            .setCanonicalGenres(new String[] {TvContract.Programs.Genres.MOVIES})
            .setContentRatings(new TvContentRating[] {TvContentRating.UNRATED})
            .setDescription("This is a sample program")
            .setEndTimeUtcMillis(1000)
            .setEpisodeNumber("Pilot", 0)
            .setEpisodeTitle("Hello World")
            .setLongDescription("This is a longer description than the previous description")
            .setPosterArtUri("http://example.com/poster.png")
            .setRecordingProhibited(false)
            .setSeasonNumber("The Final Season", 7)
            .setSeasonTitle("The Final Season")
            .setStartTimeUtcMillis(0)
            .setTitle("Google")
            .setVideoHeight(1080)
            .setVideoWidth(1920)
            .build();

    ContentValues contentValues = fullyPopulatedProgram.toContentValues();
    compareProgram(fullyPopulatedProgram, Program.fromCursor(getProgramCursor(contentValues)));

    Program clonedFullyPopulatedProgram = new Program.Builder(fullyPopulatedProgram).build();
    compareProgram(fullyPopulatedProgram, clonedFullyPopulatedProgram);
}
 
Example #10
Source File: RecordedProgram.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a RecordedProgram object from a cursor including the fields defined in {@link
 * TvContract.RecordedPrograms}.
 *
 * @param cursor A row from the TV Input Framework database.
 * @return A RecordedProgram with the values taken from the cursor.
 * @hide
 */
public static RecordedProgram fromCursor(Cursor cursor) {
    Builder builder = new Builder();
    int index = 0;
    if (!cursor.isNull(index)) {
        builder.setId(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setAudioLanguages(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setBroadcastGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setCanonicalGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setChannelId(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setContentRatings(
                TvContractUtils.stringToContentRatings(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setEndTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeDisplayNumber(
                cursor.getString(index), Integer.parseInt(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInputId(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInternalProviderData(cursor.getBlob(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setLongDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setPosterArtUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDataBytes(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDataUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDurationMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingExpireTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setSearchable(cursor.getInt(index) == IS_SEARCHABLE);
    }
    if (!cursor.isNull(++index)) {
        builder.setSeasonDisplayNumber(
                cursor.getString(index), Integer.parseInt(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setSeasonTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setShortDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setStartTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setThumbnailUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVersionNumber(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoHeight(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoWidth(cursor.getInt(index));
    }
    return builder.build();
}
 
Example #11
Source File: Program.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Program object from a cursor including the fields defined in {@link
 * TvContract.Programs}.
 *
 * @param cursor A row from the TV Input Framework database.
 * @return A Program with the values taken from the cursor.
 * @hide
 */
public static Program fromCursor(Cursor cursor) {
    Builder builder = new Builder();
    int index = 0;
    if (!cursor.isNull(index)) {
        builder.setId(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setChannelId(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeTitle(cursor.getString(index));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setSeasonNumber(cursor.getString(index), INVALID_INT_VALUE);
        }
    } else {
        if (!cursor.isNull(++index)) {
            builder.setSeasonNumber(cursor.getInt(index));
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setEpisodeNumber(cursor.getString(index), INVALID_INT_VALUE);
        }
    } else {
        if (!cursor.isNull(++index)) {
            builder.setEpisodeNumber(cursor.getInt(index));
        }
    }
    if (!cursor.isNull(++index)) {
        builder.setDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setLongDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setPosterArtUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setThumbnailUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setAudioLanguages(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setBroadcastGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setCanonicalGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setContentRatings(
                TvContractUtils.stringToContentRatings(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setStartTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEndTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoWidth((int) cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoHeight((int) cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInternalProviderData(cursor.getBlob(index));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!cursor.isNull(++index)) {
            builder.setSearchable(cursor.getInt(index) == IS_SEARCHABLE);
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setSeasonTitle(cursor.getString(index));
        }
        if (!cursor.isNull(++index)) {
            builder.setRecordingProhibited(cursor.getInt(index) == IS_RECORDING_PROHIBITED);
        }
    }
    return builder.build();
}
 
Example #12
Source File: XmlTvParser.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #13
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onPlayAdvertisement(Advertisement advertisement) {
    createPlayer(TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE,
            Uri.parse(advertisement.getRequestUrl()));
}
 
Example #14
Source File: XmlTvParser.java    From xipl with Apache License 2.0 4 votes vote down vote up
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 #15
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 4 votes vote down vote up
@Override
public void onPlayAdvertisement(Advertisement advertisement) {
    createPlayer(TvContractUtils.SOURCE_TYPE_HTTP_PROGRESSIVE,
            Uri.parse(advertisement.getRequestUrl()));
}
 
Example #16
Source File: RecordedProgram.java    From xipl with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a RecordedProgram object from a cursor including the fields defined in {@link
 * TvContract.RecordedPrograms}.
 *
 * @param cursor A row from the TV Input Framework database.
 * @return A RecordedProgram with the values taken from the cursor.
 * @hide
 */
public static RecordedProgram fromCursor(Cursor cursor) {
    Builder builder = new Builder();
    int index = 0;
    if (!cursor.isNull(index)) {
        builder.setId(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setAudioLanguages(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setBroadcastGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setCanonicalGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setChannelId(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setContentRatings(
                TvContractUtils.stringToContentRatings(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setEndTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeDisplayNumber(
                cursor.getString(index), Integer.parseInt(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInputId(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInternalProviderData(cursor.getBlob(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setLongDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setPosterArtUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDataBytes(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDataUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingDurationMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setRecordingExpireTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setSearchable(cursor.getInt(index) == IS_SEARCHABLE);
    }
    if (!cursor.isNull(++index)) {
        builder.setSeasonDisplayNumber(
                cursor.getString(index), Integer.parseInt(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setSeasonTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setShortDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setStartTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setThumbnailUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVersionNumber(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoHeight(cursor.getInt(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoWidth(cursor.getInt(index));
    }
    return builder.build();
}
 
Example #17
Source File: Program.java    From xipl with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Program object from a cursor including the fields defined in {@link
 * TvContract.Programs}.
 *
 * @param cursor A row from the TV Input Framework database.
 * @return A Program with the values taken from the cursor.
 * @hide
 */
public static Program fromCursor(Cursor cursor) {
    Builder builder = new Builder();
    int index = 0;
    if (!cursor.isNull(index)) {
        builder.setId(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setChannelId(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setTitle(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEpisodeTitle(cursor.getString(index));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setSeasonNumber(cursor.getString(index), INVALID_INT_VALUE);
        }
    } else {
        if (!cursor.isNull(++index)) {
            builder.setSeasonNumber(cursor.getInt(index));
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setEpisodeNumber(cursor.getString(index), INVALID_INT_VALUE);
        }
    } else {
        if (!cursor.isNull(++index)) {
            builder.setEpisodeNumber(cursor.getInt(index));
        }
    }
    if (!cursor.isNull(++index)) {
        builder.setDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setLongDescription(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setPosterArtUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setThumbnailUri(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setAudioLanguages(cursor.getString(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setBroadcastGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setCanonicalGenres(TvContract.Programs.Genres.decode(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setContentRatings(
                TvContractUtils.stringToContentRatings(cursor.getString(index)));
    }
    if (!cursor.isNull(++index)) {
        builder.setStartTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setEndTimeUtcMillis(cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoWidth((int) cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setVideoHeight((int) cursor.getLong(index));
    }
    if (!cursor.isNull(++index)) {
        builder.setInternalProviderData(cursor.getBlob(index));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!cursor.isNull(++index)) {
            builder.setSearchable(cursor.getInt(index) == IS_SEARCHABLE);
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (!cursor.isNull(++index)) {
            builder.setSeasonTitle(cursor.getString(index));
        }
        if (!cursor.isNull(++index)) {
            builder.setRecordingProhibited(cursor.getInt(index) == IS_RECORDING_PROHIBITED);
        }
    }
    return builder.build();
}