use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class AirPlayService method playVideo.
public void playVideo(final String url, String mimeType, String title, String description, String iconSrc, boolean shouldLoop, final LaunchListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
LaunchSession launchSession = new LaunchSession();
launchSession.setService(AirPlayService.this);
launchSession.setSessionType(LaunchSessionType.Media);
Util.postSuccess(listener, new MediaLaunchObject(launchSession, AirPlayService.this));
startTimer();
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String uri = getRequestURL("play");
String payload = null;
PListBuilder builder = new PListBuilder();
builder.putString("Content-Location", url);
builder.putReal("Start-Position", 0);
payload = builder.toString();
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, responseListener);
request.send();
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class DLNAService method sendCommand.
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
Util.runInBackground(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
String method = command.getTarget();
String payload = (String) command.getPayload();
String targetURL = null;
String serviceURN = null;
if (payload == null) {
Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"payload\" is missed", null));
return;
}
if (payload.contains(AV_TRANSPORT_URN)) {
targetURL = avTransportURL;
serviceURN = AV_TRANSPORT_URN;
} else if (payload.contains(RENDERING_CONTROL_URN)) {
targetURL = renderingControlURL;
serviceURN = RENDERING_CONTROL_URN;
} else if (payload.contains(CONNECTION_MANAGER_URN)) {
targetURL = connectionControlURL;
serviceURN = CONNECTION_MANAGER_URN;
}
if (serviceURN == null) {
Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"serviceURN\" is missed", null));
return;
}
if (targetURL == null) {
Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"targetURL\" is missed", null));
return;
}
try {
HttpConnection connection = createHttpConnection(targetURL);
connection.setHeader("Content-Type", "text/xml; charset=utf-8");
connection.setHeader("SOAPAction", String.format("\"%s#%s\"", serviceURN, method));
connection.setMethod(HttpConnection.Method.POST);
connection.setPayload(payload);
connection.execute();
int code = connection.getResponseCode();
if (code == 200) {
Util.postSuccess(command.getResponseListener(), connection.getResponseString());
} else {
Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
}
} catch (IOException e) {
Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
}
}
});
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class DLNAService method displayMedia.
public void displayMedia(String url, String subsUrl, String mimeType, String title, String description, String iconSrc, final LaunchListener listener) {
final String instanceId = "0";
String[] mediaElements = mimeType.split("/");
String mediaType = mediaElements[0];
String mediaFormat = mediaElements[1];
if (mediaType == null || mediaType.length() == 0 || mediaFormat == null || mediaFormat.length() == 0) {
Util.postError(listener, new ServiceCommandError(0, "You must provide a valid mimeType (audio/*, video/*, etc)", null));
return;
}
mediaFormat = "mp3".equals(mediaFormat) ? "mpeg" : mediaFormat;
String mMimeType = String.format("%s/%s", mediaType, mediaFormat);
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String method = "Play";
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("Speed", "1");
String payload = getMessageXml(AV_TRANSPORT_URN, method, "0", parameters);
ResponseListener<Object> playResponseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
LaunchSession launchSession = new LaunchSession();
launchSession.setService(DLNAService.this);
launchSession.setSessionType(LaunchSessionType.Media);
Util.postSuccess(listener, new MediaLaunchObject(launchSession, DLNAService.this, DLNAService.this));
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(DLNAService.this, method, payload, playResponseListener);
request.send();
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String method = "SetAVTransportURI";
String metadata = getMetadata(url, subsUrl, mMimeType, title, description, iconSrc);
if (metadata == null) {
Util.postError(listener, ServiceCommandError.getError(500));
return;
}
Map<String, String> params = new LinkedHashMap<String, String>();
try {
params.put("CurrentURI", encodeURL(url));
} catch (Exception e) {
Util.postError(listener, ServiceCommandError.getError(500));
return;
}
params.put("CurrentURIMetaData", metadata);
String payload = getMessageXml(AV_TRANSPORT_URN, method, instanceId, params);
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(DLNAService.this, method, payload, responseListener);
request.send();
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class NetcastTVService method getApplications.
private void getApplications(int type, int number, final AppListListener listener) {
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
String strObj = (String) response;
JSONArray applicationArray = parseApplicationsXmlToJSON(strObj);
List<AppInfo> appList = new ArrayList<AppInfo>();
for (int i = 0; i < applicationArray.length(); i++) {
try {
final JSONObject appJSON = applicationArray.getJSONObject(i);
AppInfo appInfo = new AppInfo() {
{
setId(appJSON.getString("id"));
setName(appJSON.getString("title"));
}
};
appList.add(appInfo);
} catch (JSONException e) {
e.printStackTrace();
}
}
Util.postSuccess(listener, appList);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_APPLIST_GET, String.valueOf(type), "0", String.valueOf(number));
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
command.setHttpMethod(ServiceCommand.TYPE_GET);
command.send();
}
use of com.connectsdk.service.command.ServiceCommand 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();
}
Aggregations