com.google.android.media.tv.companionlibrary.model.Program Java Examples

The following examples show how to use com.google.android.media.tv.companionlibrary.model.Program. 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: EpgSyncJobServiceTest.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequestSync() throws InterruptedException {
    // Tests that a sync can be requested and complete
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
            mSyncStatusChangedReceiver,
            new IntentFilter(EpgSyncJobService.ACTION_SYNC_STATUS_CHANGED));
    mSyncStatusLatch = new CountDownLatch(2);
    EpgSyncJobService.cancelAllSyncRequests(getActivity());
    EpgSyncJobService.requestImmediateSync(getActivity(), TestTvInputService.INPUT_ID,
            1000 * 60 * 60, // 1 hour sync period
            new ComponentName(getActivity(), TestJobService.class));
    mSyncStatusLatch.await();

    // Sync is completed
    List<Channel> channelList = ModelUtils.getChannels(getActivity().getContentResolver());
    Log.d("TvContractUtils", channelList.toString());
    assertEquals(2, channelList.size());
    List<Program> programList = ModelUtils.getPrograms(getActivity().getContentResolver(),
            TvContract.buildChannelUri(channelList.get(0).getId()));
    assertEquals(5, programList.size());
}
 
Example #2
Source File: XmlTvParser.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
private static TvListing parseTvListings(XmlPullParser parser)
        throws IOException, XmlPullParserException, ParseException {
    List<Channel> channels = new ArrayList<>();
    List<Program> programs = new ArrayList<>();
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_CHANNEL.equalsIgnoreCase(parser.getName())) {
            channels.add(parseChannel(parser));
        }
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_PROGRAM.equalsIgnoreCase(parser.getName())) {
            programs.add(parseProgram(parser));
        }
    }
    return new TvListing(channels, programs);
}
 
Example #3
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public void onStopRecording(Program programToRecord) {
    if (DEBUG) {
        Log.d(TAG, "onStopRecording");
    }
    // In this sample app, since all of the content is VOD, the video URL is stored.
    // If the video was live, the start and stop times should be noted using
    // RecordedProgram.Builder.setStartTimeUtcMillis and .setEndTimeUtcMillis.
    // The recordingstart time will be saved in the InternalProviderData.
    // Additionally, the stream should be recorded and saved as
    // a new file.
    long currentTime = System.currentTimeMillis();
    InternalProviderData internalProviderData = programToRecord.getInternalProviderData();
    internalProviderData.setRecordingStartTime(mStartTimeMs);
    RecordedProgram recordedProgram = new RecordedProgram.Builder(programToRecord)
                .setInputId(mInputId)
                .setRecordingDataUri(
                        programToRecord.getInternalProviderData().getVideoUrl())
                .setRecordingDurationMillis(currentTime - mStartTimeMs)
                .setInternalProviderData(internalProviderData)
                .build();
    notifyRecordingStopped(recordedProgram);
}
 
Example #4
Source File: RichTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startPosMs) {
    if (program == null) {
        requestEpgSync(getCurrentChannelUri());
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
        return false;
    }
    createPlayer(program.getInternalProviderData().getVideoType(),
            Uri.parse(program.getInternalProviderData().getVideoUrl()));
    if (startPosMs > 0) {
        mPlayer.seekTo(startPosMs);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    mPlayer.setPlayWhenReady(true);
    return true;
}
 
Example #5
Source File: XmlTvParser.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
private TvListing(List<Channel> channels, List<Program> programs) {
    this.mChannels = channels;
    this.mPrograms = new ArrayList<>(programs);
    // Place programs into the epg map
    mProgramMap = new HashMap<>();
    for (Channel channel : channels) {
        List<Program> programsForChannel = new ArrayList<>();
        Iterator<Program> programIterator = programs.iterator();
        while (programIterator.hasNext()) {
            Program program = programIterator.next();
            if (program.getChannelId() == channel.getOriginalNetworkId()) {
                programsForChannel.add(
                        new Program.Builder(program).setChannelId(channel.getId()).build());
                programIterator.remove();
            }
        }
        mProgramMap.put(channel.getOriginalNetworkId(), programsForChannel);
    }
}
 
Example #6
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 6 votes vote down vote up
private TvListing(List<Channel> channels, List<Program> programs) {
    this.mChannels = channels;
    this.mPrograms = new ArrayList<>(programs);
    // Place programs into the epg map
    mProgramMap = new HashMap<>();
    for (Channel channel: channels) {
        List<Program> programsForChannel = new ArrayList<>();
        Iterator<Program> programIterator = programs.iterator();
        while (programIterator.hasNext()) {
            Program program = programIterator.next();
            if (program.getChannelId() == channel.getOriginalNetworkId()) {
                programsForChannel.add(new Program.Builder(program)
                        .setChannelId(channel.getId())
                        .build());
                programIterator.remove();
            }
        }
        mProgramMap.put(channel.getOriginalNetworkId(), programsForChannel);
    }
}
 
Example #7
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_PLAY_CONTENT:
            mCurrentProgram = (Program) msg.obj;
            playCurrentContent();
            return true;
        case MSG_PLAY_AD:
            return insertAd((Advertisement) msg.obj);
        case MSG_PLAY_RECORDED_CONTENT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                mPlayingRecordedProgram = true;
                mRecordedProgram = (RecordedProgram) msg.obj;
                playRecordedContent();
            }
            return true;
    }
    return false;
}
 
Example #8
Source File: CumulusXmlParser.java    From CumulusTV with MIT License 6 votes vote down vote up
private static TvListing parseTvListings(XmlPullParser parser)
        throws IOException, XmlPullParserException, ParseException {
    List<Channel> channels = new ArrayList<>();
    List<Program> programs = new ArrayList<>();
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_CHANNEL.equalsIgnoreCase(parser.getName())) {
            channels.add(parseChannel(parser));
        }
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_PROGRAM.equalsIgnoreCase(parser.getName())) {
            programs.add(parseProgram(parser));
        }
    }
    return new TvListing(channels, programs);
}
 
Example #9
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    ContentResolver resolver = mContext.getContentResolver();
    Program program = null;
    long timeShiftedDifference =
            System.currentTimeMillis() - mTimeShiftedPlaybackPosition;
    if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME
            && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) {
        program = ModelUtils.getNextProgram(resolver, mChannelUri, mCurrentProgram);
    } else {
        mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;
        program = ModelUtils.getCurrentProgram(resolver, mChannelUri);
    }
    mHandler.removeMessages(MSG_PLAY_CONTENT);
    mHandler.obtainMessage(MSG_PLAY_CONTENT, program).sendToTarget();
}
 
Example #10
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    ContentResolver resolver = mContext.getContentResolver();
    Program program = null;
    long timeShiftedDifference =
            System.currentTimeMillis() - mTimeShiftedPlaybackPosition;
    if (mTimeShiftedPlaybackPosition != TvInputManager.TIME_SHIFT_INVALID_TIME
            && timeShiftedDifference > TIME_SHIFTED_MINIMUM_DIFFERENCE_MILLIS) {
        program = ModelUtils.getNextProgram(resolver, mChannelUri, mCurrentProgram);
    } else {
        mTimeShiftedPlaybackPosition = TvInputManager.TIME_SHIFT_INVALID_TIME;
        program = ModelUtils.getCurrentProgram(resolver, mChannelUri);
    }
    mHandler.removeMessages(MSG_PLAY_CONTENT);
    mHandler.obtainMessage(MSG_PLAY_CONTENT, program).sendToTarget();
}
 
Example #11
Source File: XmlTvParser.java    From xipl with Apache License 2.0 6 votes vote down vote up
private static TvListing parseTvListings(XmlPullParser parser)
        throws IOException, XmlPullParserException, ParseException {
    List<Channel> channels = new ArrayList<>();
    List<Program> programs = new ArrayList<>();
    while (parser.next() != XmlPullParser.END_DOCUMENT) {
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_CHANNEL.equalsIgnoreCase(parser.getName())) {
            Channel channel = parseChannel(parser);
            if (channel != null) {
                channels.add(channel);
            }
        }
        if (parser.getEventType() == XmlPullParser.START_TAG
                && TAG_PROGRAM.equalsIgnoreCase(parser.getName())) {
            Program program = parseProgram(parser);
            if (program != null) {
                programs.add(program);
            }
        }
    }
    return new TvListing(channels, programs);
}
 
Example #12
Source File: XmlTvParser.java    From xipl with Apache License 2.0 6 votes vote down vote up
private TvListing(List<Channel> channels, List<Program> programs) {
    this.mChannels = channels;
    this.mPrograms = new ArrayList<>(programs);
    // Place programs into the epg map
    mProgramMap = new HashMap<>();
    for (Channel channel : channels) {
        List<Program> programsForChannel = new ArrayList<>();
        Iterator<Program> programIterator = programs.iterator();
        while (programIterator.hasNext()) {
            Program program = programIterator.next();
            if (program.getChannelId() == channel.getOriginalNetworkId()) {
                programsForChannel.add(
                        new Program.Builder(program).setChannelId(channel.getId()).build());
                programIterator.remove();
            }
        }
        // Don't overwrite a channel's programs list if a key was already existent
        if (!mProgramMap.containsKey(channel.getOriginalNetworkId())) {
            mProgramMap.put(channel.getOriginalNetworkId(), programsForChannel);
        }
    }
}
 
Example #13
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_PLAY_CONTENT:
            mCurrentProgram = (Program) msg.obj;
            playCurrentContent();
            return true;
        case MSG_PLAY_AD:
            return insertAd((Advertisement) msg.obj);
        case MSG_PLAY_RECORDED_CONTENT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                mPlayingRecordedProgram = true;
                mRecordedProgram = (RecordedProgram) msg.obj;
                playRecordedContent();
            }
            return true;
    }
    return false;
}
 
Example #14
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatProgramDuration() {
    // If repeat-programs is on, schedule the programs sequentially in a loop. To make every
    // device play the same program in a given channel and time, we assumes the loop started
    // from the epoch time.
    long totalDurationMs = 0;
    for (Program program : mProgramList) {
        totalDurationMs += (program.getEndTimeUtcMillis() - program.getStartTimeUtcMillis());
        assertTrue(program.getEndTimeUtcMillis() >= program.getStartTimeUtcMillis());
    }
    long programStartTimeMs = mStartMs - mStartMs % totalDurationMs;
    assertNotSame(0, totalDurationMs);
    assertTrue(programStartTimeMs > 0);
    assertTrue(programStartTimeMs <= mStartMs);
}
 
Example #15
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());
}
 
Example #16
Source File: EpgSyncTest.java    From CumulusTV with MIT License 5 votes vote down vote up
/**
 * From a resource file, we will try to pull EPG data for a channel.
 */
@Test
public void testPullFromXmlTvResource() throws JSONException, InterruptedException {
    VolatileChannelDatabase.getMockedInstance(getActivity()).add(
            new JsonChannel.Builder()
                    .setName("Name")
                    .setNumber("Number")
                    .setMediaUrl(MEDIA_URL)
                    .setEpgUrl("http://example.com/epg.xml")
                    .setLogo("http://static-cdn1.ustream.tv/i/channel/picture/9/4/0/8/9408562/9408562_iss_hr_1330361780,256x144,r:1.jpg")
                    .build());
    CumulusJobService.requestImmediateSync1(getActivity(),
            "com.felkertech.cumulustv.tv.CumulusTvTifService", CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
            new ComponentName(getActivity(), CumulusJobService.class));
    // Wait for sync to complete
    Thread.sleep(1000 * 10);
    ChannelDatabase channelDatabase = VolatileChannelDatabase.getMockedInstance(getActivity());

    // Get our channel row
    Thread.sleep(1000 * 5);
    HashMap<String, Long> databaseRowMap = channelDatabase.getHashMap();
    assertTrue(databaseRowMap.containsKey(MEDIA_URL));
    long rowId = databaseRowMap.get(MEDIA_URL);
    assertTrue(rowId > 0);

    // Get programs
    Cursor cursor = getActivity().getContentResolver().query(
            TvContract.buildProgramsUriForChannel(rowId), null, null, null, null);
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    Program program = Program.fromCursor(cursor);
    if (!(program.getTitle().equals("Elephants Dream") ||
            program.getTitle().equals("Sintel"))) {
        Assert.fail("Neither program was found.");
    }
}
 
Example #17
Source File: EpgSyncWithAdsJobService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
/**
 * Calls {@link #getOriginalProgramsForChannel(Uri, Channel, long, long)} and then repeats and
 * inserts ads as needed.
 */
@Override
public final List<Program> getProgramsForChannel(
        Uri channelUri, Channel channel, long startMs, long endMs) throws EpgSyncException {
    return repeatAndInsertAds(
            channel,
            getOriginalProgramsForChannel(channelUri, channel, startMs, endMs),
            startMs,
            endMs);
}
 
Example #18
Source File: EpgSyncWithAdsJobServiceTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestSync() throws InterruptedException {
    // Tests that a sync can be requested and complete
    LocalBroadcastManager.getInstance(getActivity())
            .registerReceiver(
                    mSyncStatusChangedReceiver,
                    new IntentFilter(EpgSyncJobService.ACTION_SYNC_STATUS_CHANGED));
    mSyncStatusLatch = new CountDownLatch(2);
    EpgSyncJobService.cancelAllSyncRequests(getActivity());
    EpgSyncJobService.requestImmediateSync(
            getActivity(),
            TestTvInputService.INPUT_ID,
            1000 * 60 * 60, // 1 hour sync period
            new ComponentName(getActivity(), TestJobService.class));
    mSyncStatusLatch.await();

    // Sync is completed
    List<Channel> channelList = ModelUtils.getChannels(getActivity().getContentResolver());
    Log.d("TvContractUtils", channelList.toString());
    assertEquals(2, channelList.size());
    List<Program> programList =
            ModelUtils.getPrograms(
                    getActivity().getContentResolver(),
                    TvContract.buildChannelUri(channelList.get(0).getId()));
    assertEquals(5, programList.size());
}
 
Example #19
Source File: EpgSyncWithAdsJobService.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * Calls {@link #getOriginalProgramsForChannel(Uri, Channel, long, long)} and then repeats and
 * inserts ads as needed.
 */
@Override
public final List<Program> getProgramsForChannel(
        Uri channelUri, Channel channel, long startMs, long endMs) throws EpgSyncException {
    return repeatAndInsertAds(
            channel,
            getOriginalProgramsForChannel(channelUri, channel, startMs, endMs),
            startMs,
            endMs);
}
 
Example #20
Source File: TestTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopRecording(Program programToRecord) {
    mIsRecording = false;
    // Add a sample program into our DVR
    notifyRecordingStopped(new RecordedProgram.Builder()
            .setInputId(mInputId)
            .setTitle("That Gmail Blue Video")
            .setRecordingDataUri(TestJobService.GMAIL_BLUE_VIDEO_URL)
            .setStartTimeUtcMillis(System.currentTimeMillis())
            .setEndTimeUtcMillis(System.currentTimeMillis() + 1000 * 60 * 60)
            .build());
}
 
Example #21
Source File: CumulusTvTifService.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startPosMs) {
    if (program == null) {
        requestEpgSync(getCurrentChannelUri());
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_TUNING);
        return false;
    }
    jsonChannel = ChannelDatabase.getInstance(getApplicationContext()).findChannelByMediaUrl(
            program.getInternalProviderData().getVideoUrl());
    Log.d(TAG, "Play program " + program.getTitle() + " " +
            program.getInternalProviderData().getVideoUrl());
    if (program.getInternalProviderData().getVideoUrl() == null) {
        Toast.makeText(mContext, getString(R.string.msg_no_url_found), Toast.LENGTH_SHORT).show();
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        return false;
    } else {
        createPlayer(program.getInternalProviderData().getVideoType(),
                Uri.parse(program.getInternalProviderData().getVideoUrl()));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
        }
        mPlayer.play();
        notifyVideoAvailable();
        Log.d(TAG, "The video should start playing");
        return true;
    }
}
 
Example #22
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 #23
Source File: EpgSyncJobServiceTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Test
public void testEpgSyncTask_GetPrograms() {
    // For repeating channels, test that the program list will continually repeat for the
    // desired length of time
    Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
    Channel firstChannel = mChannelList.get(0);
    TestJobService.TestEpgSyncTask epgSyncTask = mSampleJobService.getDefaultEpgSyncTask();
    mProgramList = mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs,
            mEndMs);
    List<Program> continuousProgramsList = epgSyncTask.getPrograms(
            firstChannel, mProgramList, mStartMs, mEndMs);
    // There are 336 hours in a two week period, and each program is 15m long
    assertEquals(336 * 60 / 15, continuousProgramsList.size());
}
 
Example #24
Source File: EpgSyncJobServiceTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatProgramDuration() {
    // If repeat-programs is on, schedule the programs sequentially in a loop. To make every
    // device play the same program in a given channel and time, we assumes the loop started
    // from the epoch time.
    long totalDurationMs = 0;
    for (Program program : mProgramList) {
        totalDurationMs += (program.getEndTimeUtcMillis() - program.getStartTimeUtcMillis());
        assertTrue(program.getEndTimeUtcMillis() >= program.getStartTimeUtcMillis());
    }
    long programStartTimeMs = mStartMs - mStartMs % totalDurationMs;
    assertNotSame(0, totalDurationMs);
    assertTrue(programStartTimeMs > 0);
    assertTrue(programStartTimeMs <= mStartMs);
}
 
Example #25
Source File: TestTvInputService.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopRecording(Program programToRecord) {
    mIsRecording = false;
    // Add a sample program into our DVR
    notifyRecordingStopped(new RecordedProgram.Builder()
            .setInputId(mInputId)
            .setTitle("That Gmail Blue Video")
            .setRecordingDataUri(TestJobService.GMAIL_BLUE_VIDEO_URL)
            .setStartTimeUtcMillis(System.currentTimeMillis())
            .setEndTimeUtcMillis(System.currentTimeMillis() + 1000 * 60 * 60)
            .build());
}
 
Example #26
Source File: TestTvInputService.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startMs) {
    if (program == null) {
        return false;
    } else {
        mProgram = program;
        Assert.assertNotNull("There is no internal provider data",
                mProgram.getInternalProviderData());
        String videoUrl = program.getInternalProviderData().getVideoUrl();
        return playMediaUrl(videoUrl);
    }
}
 
Example #27
Source File: EpgSyncJobService.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the {@code oldProgram} program is the same as the {@code newProgram}
 * program but should update metadata. This updates the database instead of deleting and
 * inserting a new program to keep the user's intent, eg. recording this program.
 */
public boolean shouldUpdateProgramMetadata(Program oldProgram, Program newProgram) {
    // NOTE: Here, we update the old program if it has the same title and overlaps with the
    // new program. The test logic is just an example and you can modify this. E.g. check
    // whether the both programs have the same program ID if your EPG supports any ID for
    // the programs.
    return oldProgram.getTitle().equals(newProgram.getTitle())
            && oldProgram.getStartTimeUtcMillis() <= newProgram.getEndTimeUtcMillis()
            && newProgram.getStartTimeUtcMillis() <= oldProgram.getEndTimeUtcMillis();
}
 
Example #28
Source File: EpgSyncJobService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the {@code oldProgram} program is the same as the {@code newProgram}
 * program but should update metadata. This updates the database instead of deleting and
 * inserting a new program to keep the user's intent, eg. recording this program.
 */
public boolean shouldUpdateProgramMetadata(Program oldProgram, Program newProgram) {
    // NOTE: Here, we update the old program if it has the same title and overlaps with the
    // new program. The test logic is just an example and you can modify this. E.g. check
    // whether the both programs have the same program ID if your EPG supports any ID for
    // the programs.
    return oldProgram.getTitle().equals(newProgram.getTitle())
            && oldProgram.getStartTimeUtcMillis() <= newProgram.getEndTimeUtcMillis()
            && newProgram.getStartTimeUtcMillis() <= oldProgram.getEndTimeUtcMillis();
}
 
Example #29
Source File: TestTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPlayProgram(Program program, long startMs) {
    if (program == null) {
        return false;
    } else {
        mProgram = program;
        Assert.assertNotNull("There is no internal provider data",
                mProgram.getInternalProviderData());
        String videoUrl = program.getInternalProviderData().getVideoUrl();
        return playMediaUrl(videoUrl);
    }
}
 
Example #30
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);
    }
}