下面列出了android.database.CursorIndexOutOfBoundsException#com.google.android.media.tv.companionlibrary.model.Channel 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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);
}
}
}
@Test
public void testChannelsProgramSync() {
// Tests that programs and channels were correctly obtained from the EpgSyncJobService
Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
Channel firstChannel = mChannelList.get(0);
assertEquals("Test Channel", firstChannel.getDisplayName());
assertNotNull(firstChannel.getInternalProviderData());
assertTrue(firstChannel.getInternalProviderData().isRepeatable());
mProgramList = mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs,
mEndMs);
assertEquals(1, mProgramList.size());
channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(1));
Channel secondChannel = mChannelList.get(1);
assertEquals("XML Test Channel", secondChannel.getDisplayName());
assertNotNull(secondChannel.getInternalProviderData());
assertTrue(secondChannel.getInternalProviderData().isRepeatable());
mProgramList = mSampleJobService.getProgramsForChannel(channelUri, secondChannel, mStartMs,
mEndMs);
assertEquals(5, mProgramList.size());
}
@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());
}
@Override
public void onPlayChannel(Channel channel) {
if (channel.getInternalProviderData() != null) {
mProviderTvPlayer = new ProviderTvPlayer(mContext, channel.getInternalProviderData().getVideoUrl());
mProviderTvPlayer.addListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNSUPPORTED);
}
if (DEBUG) {
Log.d(getClass().getSimpleName(), "Video Url: " + channel.getInternalProviderData().getVideoUrl());
Log.d(getClass().getSimpleName(), "Video format: " + channel.getVideoFormat());
}
// Notify when the video is available so the channel surface can be shown to the screen.
mProviderTvPlayer.play();
} else {
Toast.makeText(mContext, R.string.channel_stream_failure, Toast.LENGTH_SHORT).show();
}
}
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);
}
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);
}
}
@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
ChannelDatabase channelDatabase = ChannelDatabase.getInstance(getApplicationContext());
if (parentId.equals(MEDIA_ROOT_ID)) {
try {
for (Channel channel : channelDatabase.getChannels()) {
MediaDescriptionCompat descriptionCompat = new MediaDescriptionCompat.Builder()
.setMediaId(channel.getInternalProviderData().getVideoUrl())
.setTitle(channel.getDisplayName())
.setIconUri(Uri.parse(channel.getChannelLogo()))
.setSubtitle(getString(R.string.channel_no_xxx, channel.getDisplayNumber()))
.setDescription(channel.getDescription())
.setMediaUri(Uri.parse(channel.getInternalProviderData().getVideoUrl()))
.build();
mediaItems.add(new MediaBrowserCompat.MediaItem(descriptionCompat,
MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
}
result.sendResult(mediaItems);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
/**
* Tests that we can use the .toChannel method to successfully create a channel object.
*/
@Test
public void testSuccessfulChannelConversion() {
JsonChannel jsonChannel = new JsonChannel.Builder()
.setAudioOnly(AUDIO_ONLY)
.setEpgUrl(EPG_URL)
.setGenres(GENRES)
.setLogo(LOGO)
.setMediaUrl(MEDIA_URL)
.setName(NAME)
.setNumber(NUMBER)
.setSplashscreen(SPLASHSCREEN)
.build();
Channel channel = jsonChannel.toChannel();
assertEquals(channel.getDisplayName(), jsonChannel.getName());
}
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);
}
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);
}
}
@Test
public void testOriginalChannelsProgramSync() throws EpgSyncException {
// Tests that programs and channels were correctly obtained from the EpgSyncJobService
Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
Channel firstChannel = mChannelList.get(0);
assertEquals("Test Channel", firstChannel.getDisplayName());
assertNotNull(firstChannel.getInternalProviderData());
assertTrue(firstChannel.getInternalProviderData().isRepeatable());
mProgramList =
mSampleJobService.getOriginalProgramsForChannel(
channelUri, firstChannel, mStartMs, mEndMs);
assertEquals(1, mProgramList.size());
channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(1));
Channel secondChannel = mChannelList.get(1);
assertEquals("XML Test Channel", secondChannel.getDisplayName());
assertNotNull(secondChannel.getInternalProviderData());
assertTrue(secondChannel.getInternalProviderData().isRepeatable());
mProgramList =
mSampleJobService.getOriginalProgramsForChannel(
channelUri, secondChannel, mStartMs, mEndMs);
assertEquals(5, mProgramList.size());
}
@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());
}
/**
* 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);
}
@Override
public void onStopRecordingChannel(Channel channelToRecord) {
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());
}
@Override
public void beforeActivityLaunched() {
super.beforeActivityLaunched();
getActivity();
// Delete all channels
getActivity().getContentResolver().delete(TvContract.buildChannelsUriForInput(
TestTvInputService.INPUT_ID), null, null);
mSampleJobService = new TestJobService();
mSampleJobService.mContext = getActivity();
mChannelList = mSampleJobService.getChannels();
ModelUtils.updateChannels(getActivity(), TestTvInputService.INPUT_ID, mChannelList, null);
mChannelMap = ModelUtils.buildChannelMap(getActivity().getContentResolver(),
TestTvInputService.INPUT_ID);
assertNotNull(mChannelMap);
assertEquals(2, mChannelMap.size());
// Round start time to the current hour
mStartMs = System.currentTimeMillis() - System.currentTimeMillis() % (1000 * 60 * 60);
mEndMs = mStartMs + 1000 * 60 * 60 * 24 * 7 * 2; // Two week long sync period
assertTrue(mStartMs < mEndMs);
Uri channelUri = TvContract.buildChannelUri(mChannelMap.keyAt(0));
Channel firstChannel = mChannelList.get(0);
assertEquals("Test Channel", firstChannel.getDisplayName());
assertNotNull(firstChannel.getInternalProviderData());
assertTrue(firstChannel.getInternalProviderData().isRepeatable());
mProgramList = mSampleJobService.getProgramsForChannel(channelUri, firstChannel, mStartMs,
mEndMs);
}
@Test
public void testJobService() {
// Tests whether methods to get channels and programs are successful and valid
List<Channel> channelList = mSampleJobService.getChannels();
assertEquals(2, channelList.size());
ModelUtils.updateChannels(getActivity(), TestTvInputService.INPUT_ID, channelList, null);
LongSparseArray<Channel> channelMap = ModelUtils.buildChannelMap(
getActivity().getContentResolver(), TestTvInputService.INPUT_ID);
assertNotNull(channelMap);
assertEquals(channelMap.size(), channelList.size());
}
@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());
}
@Override
public List<Channel> getChannels() {
Assert.assertNotNull("Please set the static mContext before running", mContext);
// Wrap our list in an ArrayList so we will be able to make modifications if necessary
Assert.assertNotNull("Set TestJobService.mContext.", mContext);
InternalProviderData internalProviderData = new InternalProviderData();
internalProviderData.setRepeatable(true);
ArrayList<Channel> testChannels = new ArrayList<>();
testChannels.add(new Channel.Builder()
.setOriginalNetworkId(0)
.setDisplayName("Test Channel")
.setDisplayNumber("1")
.setInternalProviderData(internalProviderData)
.build());
// Add an XML parsed channel
Uri xmlUri = Uri.parse("android.resource://" + mContext.getPackageName()
+ "/" + com.google.android.media.tv.companionlibrary.test.R.raw.xmltv)
.normalizeScheme();
try {
InputStream inputStream = mContext.getContentResolver()
.openInputStream(xmlUri);
Assert.assertNotNull(inputStream);
testChannels.addAll(XmlTvParser.parse(inputStream).getChannels());
} catch (FileNotFoundException | XmlTvParser.XmlTvParseException e) {
throw new RuntimeException("Exception found of type " + e.getClass().getCanonicalName()
+ ": " + e.getMessage());
}
return testChannels;
}
@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());
}
@Override
public void onProcessSuccess(List<Channel> channels, XmlTvParser.TvListing listing) {
mChannels = channels;
mTvListing = listing;
EpgSyncTask epgSyncTask = new EpgSyncTask(mJobParameters);
epgSyncTask.execute();
}
/**
* Gets a list of channels based on the M3U playlist of a given user.
*
* @param playlist List of the playlist lines containing the user's channels
* @param context the context required for some other operations (Getting the genre for example)
* @return the list of channels for a given user
*/
public static List<Channel> createChannelList(InputStream playlist, Context context, ChannelProperties properties) {
List<AvContent> channelContents = AvContentUtil.getAvContentsList(playlist);
List<Channel> tempList = new ArrayList<>();
int channelNumber = 1;
/*
Google is kind of "weird" when it comes to the way it has of tuning channel/program
data. In most cases, the TIF expects to have a program available for each channels in order
to play them.
However, a provider might not have all programs available for a given channel so simply save the EPG
id and leave the parsing to when programs will get created.
*/
for (int i = 0; i < channelContents.size(); i++) {
Channel channel;
String tempName = channelContents.get(i).getTitle();
String tempLogo = channelContents.get(i).getLogo();
String tempLink = channelContents.get(i).getContentLink();
String tempGroup = channelContents.get(i).getGroup();
int tempId = channelContents.get(i).getId();
if (properties.hasChannelLogo()) {
channel = createChannel(tempName, Integer.toString(i + 1), tempId, tempLogo, tempLink, tempGroup, getProgramGenre(tempName, context));
} else {
channel = createChannel(tempName, Integer.toString(i + 1), tempId, null, tempLink, tempGroup, getProgramGenre(tempName, context));
}
// Some users might have playlist items that aren't valid channels, remove them.
if (properties.isLiveChannel(channel) && properties.isChannelRegionValid(channel) && properties.isChannelGenreValid(channel) && properties.isChannelGroupValid(channel)) {
// Some channels might get filtered so let's use a counter which will only register "valid" ones.
channel = createChannel(channel, Integer.toString(channelNumber));
tempList.add(channel);
channelNumber++;
}
}
return (tempList);
}
/**
* 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());
}
public List<Channel> getChannels() throws JSONException {
List<JsonChannel> jsonChannelList = getJsonChannels();
List<Channel> channelList = new ArrayList<>();
for (int i = 0; i < jsonChannelList.size(); i++) {
JsonChannel jsonChannel = jsonChannelList.get(i);
Channel channel = jsonChannel.toChannel();
channelList.add(channel);
}
return channelList;
}
public List<Channel> getChannels(InternalProviderData providerData) throws JSONException {
List<JsonChannel> jsonChannelList = getJsonChannels();
List<Channel> channelList = new ArrayList<>();
for (int i = 0; i < jsonChannelList.size(); i++) {
JsonChannel jsonChannel = jsonChannelList.get(i);
Channel channel = jsonChannel.toChannel(providerData);
channelList.add(channel);
}
return channelList;
}
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();
}
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();
}
@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;
}
/**
* Test generating a {@link JsonChannel} and inserting that correctly.
*/
@Test
public void testJsonChannelConverter() {
JsonChannel jsonChannel = new JsonChannel.Builder()
.setName("Hello")
.setMediaUrl(MEDIA_URL)
.setNumber("1234")
.build();
Channel channel = jsonChannel.toChannel();
// This cannot be done until we update the Channel model.
}
@Override
public List<Channel> getChannels() throws JSONException {
List<Channel> channelList = new ArrayList<>();
for (int i = 0; i < mJsonChannels.size(); i++) {
JsonChannel jsonChannel = (JsonChannel) mJsonChannels.get(i);
Channel channel = jsonChannel.toChannel();
channelList.add(channel);
}
return channelList;
}