use of com.connectsdk.service.netcast.NetcastChannelParser in project butter-android by butterproject.
the class NetcastTVService method getChannelList.
@Override
public void getChannelList(final ChannelListListener listener) {
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CHANNEL_LIST);
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
SAXParser saxParser = saxParserFactory.newSAXParser();
NetcastChannelParser parser = new NetcastChannelParser();
saxParser.parse(stream, parser);
JSONArray channelArray = parser.getJSONChannelArray();
ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>();
for (int i = 0; i < channelArray.length(); i++) {
JSONObject rawData;
try {
rawData = (JSONObject) channelArray.get(i);
ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
channelList.add(channel);
} catch (JSONException e) {
e.printStackTrace();
}
}
Util.postSuccess(listener, channelList);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
request.setHttpMethod(ServiceCommand.TYPE_GET);
request.send();
}
use of com.connectsdk.service.netcast.NetcastChannelParser in project butter-android by butterproject.
the class NetcastTVService method getCurrentChannel.
@Override
public void getCurrentChannel(final ChannelListener listener) {
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CURRENT_CHANNEL);
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
SAXParser saxParser = saxParserFactory.newSAXParser();
NetcastChannelParser parser = new NetcastChannelParser();
saxParser.parse(stream, parser);
JSONArray channelArray = parser.getJSONChannelArray();
if (channelArray.length() > 0) {
JSONObject rawData = (JSONObject) channelArray.get(0);
ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
Util.postSuccess(listener, channel);
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
request.send();
}
Aggregations