Java Code Examples for com.google.android.media.tv.companionlibrary.model.InternalProviderData#getAds()

The following examples show how to use com.google.android.media.tv.companionlibrary.model.InternalProviderData#getAds() . 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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: XmlTvAdvertisementTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvertisementParsing() throws XmlTvParser.XmlTvParseException, ParseException {
    long epochStartTime = 0;
    String requestUrl1 = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480" +
            "&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s" +
            "&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1" +
            "&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=";
    String requestUrl2 = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480" +
            "&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s" +
            "&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1" +
            "&cust_params=deployment%3Ddevsite%26sample_ct%3Dredirectlinear&correlator=";
    String testXmlFile = "xmltv.xml";
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile);
    XmlTvParser.TvListing listings = XmlTvParser.parse(inputStream);
    // Channel 1 should have one VAST advertisement.
    Channel adChannel = listings.getChannels().get(1);
    assertNotNull(adChannel.getInternalProviderData());
    List<Advertisement> adChannelAds = adChannel.getInternalProviderData().getAds();
    assertEquals(1, adChannelAds.size());
    assertEquals(epochStartTime, adChannelAds.get(0).getStartTimeUtcMillis());
    assertEquals(epochStartTime, adChannelAds.get(0).getStopTimeUtcMillis());
    assertEquals(Advertisement.TYPE_VAST, adChannelAds.get(0).getType());
    // Channel 0 should not have any advertisement.
    Channel noAdChannel = listings.getChannels().get(0);
    assertNotNull(noAdChannel.getInternalProviderData());
    List<Advertisement> noAdChannelAds = noAdChannel.getInternalProviderData().getAds();
    assertEquals(0, noAdChannelAds.size());
    // Program 7 should have 2 advertisements with different request tags.
    Program adProgram = listings.getAllPrograms().get(7);
    assertNotNull(adProgram.getInternalProviderData());
    InternalProviderData adProgramData = adProgram.getInternalProviderData();
    List<Advertisement> adProgramAds = adProgramData.getAds();
    assertEquals(2, adProgramAds.size());
    assertEquals(requestUrl1, adProgramAds.get(0).getRequestUrl());
    assertEquals(requestUrl2, adProgramAds.get(1).getRequestUrl());
}
 
Example 5
Source File: XmlTvAdvertisementTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvertisementParsing() throws XmlTvParser.XmlTvParseException, ParseException {
    long epochStartTime = 0;
    String requestUrl1 = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480" +
            "&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s" +
            "&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1" +
            "&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=";
    String requestUrl2 = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480" +
            "&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s" +
            "&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1" +
            "&cust_params=deployment%3Ddevsite%26sample_ct%3Dredirectlinear&correlator=";
    String testXmlFile = "xmltv.xml";
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(testXmlFile);
    XmlTvParser.TvListing listings = XmlTvParser.parse(inputStream);
    // Channel 1 should have one VAST advertisement.
    Channel adChannel = listings.getChannels().get(1);
    assertNotNull(adChannel.getInternalProviderData());
    List<Advertisement> adChannelAds = adChannel.getInternalProviderData().getAds();
    assertEquals(1, adChannelAds.size());
    assertEquals(epochStartTime, adChannelAds.get(0).getStartTimeUtcMillis());
    assertEquals(epochStartTime, adChannelAds.get(0).getStopTimeUtcMillis());
    assertEquals(Advertisement.TYPE_VAST, adChannelAds.get(0).getType());
    // Channel 0 should not have any advertisement.
    Channel noAdChannel = listings.getChannels().get(0);
    assertNotNull(noAdChannel.getInternalProviderData());
    List<Advertisement> noAdChannelAds = noAdChannel.getInternalProviderData().getAds();
    assertEquals(0, noAdChannelAds.size());
    // Program 7 should have 2 advertisements with different request tags.
    Program adProgram = listings.getAllPrograms().get(7);
    assertNotNull(adProgram.getInternalProviderData());
    InternalProviderData adProgramData = adProgram.getInternalProviderData();
    List<Advertisement> adProgramAds = adProgramData.getAds();
    assertEquals(2, adProgramAds.size());
    assertEquals(requestUrl1, adProgramAds.get(0).getRequestUrl());
    assertEquals(requestUrl2, adProgramAds.get(1).getRequestUrl());
}