Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Added support for custom data in the MediaInfo object class + other fix #92

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/com/connectsdk/core/MediaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MediaInfo {
private String mimeType;
private String description;
private String title;
private Object customData;

/**
* list of imageInfo objects where [0] is icon, [1] is poster
Expand All @@ -61,6 +62,7 @@ public static class Builder {
private String description;
private List<ImageInfo> allImages;
private SubtitleInfo subtitleInfo;
private Object customData;

// @endcond

Expand Down Expand Up @@ -100,6 +102,11 @@ public Builder setSubtitleInfo(@NonNull SubtitleInfo subtitleInfo) {
return this;
}

public Builder setCustomData(@NonNull Object customData) {
this.customData = customData;
return this;
}

public MediaInfo build() {
return new MediaInfo(this);
}
Expand All @@ -119,6 +126,7 @@ private MediaInfo(MediaInfo.Builder builder) {
description = builder.description;
subtitleInfo = builder.subtitleInfo;
allImages = builder.allImages;
customData = builder.customData;
}

/**
Expand Down Expand Up @@ -274,4 +282,14 @@ public void addImages(ImageInfo... images) {
this.setImages(list);
}

/** Gets the raw data associated to this MediaInfo. In most cases, this is a Map or JSONObject. */
public Object getCustomData() {
return customData;
}

/** Sets the raw data associated to this MediaInfo.. In most cases, this is a Map or JSONObject. */
public void setCustomData(Object customData) {
this.customData = customData;
}

}
20 changes: 20 additions & 0 deletions src/com/connectsdk/device/ConnectableDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ public ConnectableDevice(JSONObject json) {
setLastSeenOnWifi(json.optString(KEY_LAST_SEEN, null));
setLastConnected(json.optLong(KEY_LAST_CONNECTED, 0));
setLastDetection(json.optLong(KEY_LAST_DETECTED, 0));

//Deserialize the associated services as well
JSONObject jsonServices = json.optJSONObject(KEY_SERVICES);
if(jsonServices!=null) {
Iterator<?> keys = jsonServices.keys();
if (keys != null) {
while (keys.hasNext()) {
String key = (String) keys.next();
JSONObject serviceObject = jsonServices.optJSONObject(key);
if (serviceObject!=null) {
DeviceService service = DeviceService.getService(serviceObject);
addService(service);
}
}
}
}

}

public static ConnectableDevice createFromConfigString(String ipAddress, String friendlyName, String modelName, String modelNumber) {
Expand Down Expand Up @@ -816,6 +833,9 @@ public void update(ServiceDescription description) {
setModelName(description.getModelName());
setModelNumber(description.getModelNumber());
setLastConnected(description.getLastDetection());

if(description.getUUID()!=null && description.getUUID().length()>0)
setId(description.getUUID());
}

public JSONObject toJSONObject() {
Expand Down
14 changes: 7 additions & 7 deletions src/com/connectsdk/discovery/DiscoveryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,16 @@ public void handleDeviceAdd(ConnectableDevice device) {

compatibleDevices.put(device.getIpAddress(), device);

for (DiscoveryManagerListener listenter: discoveryListeners) {
listenter.onDeviceAdded(this, device);
for (DiscoveryManagerListener listener: discoveryListeners) {
listener.onDeviceAdded(this, device);
}
}

public void handleDeviceUpdate(ConnectableDevice device) {
if (deviceIsCompatible(device)) {
if (device.getIpAddress() != null && compatibleDevices.containsKey(device.getIpAddress())) {
for (DiscoveryManagerListener listenter: discoveryListeners) {
listenter.onDeviceUpdated(this, device);
for (DiscoveryManagerListener listener: discoveryListeners) {
listener.onDeviceUpdated(this, device);
}
}
else {
Expand All @@ -613,8 +613,8 @@ public void handleDeviceUpdate(ConnectableDevice device) {
}

public void handleDeviceLoss(ConnectableDevice device) {
for (DiscoveryManagerListener listenter: discoveryListeners) {
listenter.onDeviceRemoved(this, device);
for (DiscoveryManagerListener listener: discoveryListeners) {
listener.onDeviceRemoved(this, device);
}

device.disconnect();
Expand Down Expand Up @@ -732,7 +732,6 @@ public void onServiceAdded(DiscoveryProvider provider, ServiceDescription servic

if (device == null) {
device = new ConnectableDevice(serviceDescription);
device.setIpAddress(serviceDescription.getIpAddress());
allDevices.put(serviceDescription.getIpAddress(), device);
deviceIsNew = true;
}
Expand Down Expand Up @@ -850,6 +849,7 @@ public void addServiceDescriptionToDevice(ServiceDescription desc, ConnectableDe
if (deviceService != null) {
deviceService.setServiceDescription(desc);
device.addService(deviceService);
device.setServiceDescription(desc);
}
}
// @endcond
Expand Down
10 changes: 10 additions & 0 deletions src/com/connectsdk/service/AirPlayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,16 @@ public void playMedia(String url, String mimeType, String title,

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, 0, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, startPosition, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, LaunchListener listener) {
String mediaUrl = null;
String mimeType = null;
String title = null;
Expand Down
13 changes: 11 additions & 2 deletions src/com/connectsdk/service/DLNAService.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,17 @@ public void playMedia(String url, String mimeType, String title, String descript
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop,
LaunchListener listener) {
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, 0, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, startPosition, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, LaunchListener listener) {
String mediaUrl = null;
SubtitleInfo subtitle = null;
String mimeType = null;
Expand Down
10 changes: 10 additions & 0 deletions src/com/connectsdk/service/NetcastTVService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,16 @@ public void playMedia(String url, String mimeType, String title, String descript

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, 0, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, startPosition, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, final LaunchListener listener) {
if (getDLNAService() != null) {
final MediaPlayer.LaunchListener launchListener = new LaunchListener() {

Expand Down
13 changes: 11 additions & 2 deletions src/com/connectsdk/service/RokuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,17 @@ public void playMedia(String url, String mimeType, String title,
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop,
MediaPlayer.LaunchListener listener) {
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, MediaPlayer.LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, 0, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, startPosition, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, LaunchListener listener) {
String mediaUrl = null;
String mimeType = null;
String title = null;
Expand Down
18 changes: 16 additions & 2 deletions src/com/connectsdk/service/WebOSTVService.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ private DeviceService getDLNAService() {
return service;
}

@Override
public String getWebAppId() {
return MEDIA_PLAYER_ID;
}

public static DiscoveryFilter discoveryFilter() {
return new DiscoveryFilter(ID, "urn:lge-com:service:webos-second-screen:1");
}
Expand Down Expand Up @@ -1293,8 +1298,17 @@ public void playMedia(String url, String mimeType, String title, String descript
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop,
MediaPlayer.LaunchListener listener) {
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, MediaPlayer.LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, 0, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener) {
playMedia(mediaInfo, shouldLoop, startPosition, null, listener);
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, LaunchListener listener) {
if ("4.0.0".equalsIgnoreCase(this.serviceDescription.getVersion())) {
playMediaByNativeApp(mediaInfo, shouldLoop, listener);
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/com/connectsdk/service/capability/MediaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.connectsdk.service.command.ServiceSubscription;
import com.connectsdk.service.sessions.LaunchSession;

import org.json.JSONObject;

public interface MediaPlayer extends CapabilityMethods {
public final static String Any = "MediaPlayer.Any";

Expand Down Expand Up @@ -82,6 +84,10 @@ public interface MediaPlayer extends CapabilityMethods {

public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, LaunchListener listener);

public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, LaunchListener listener);

public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, LaunchListener listener);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Object customData? It isn't used anywhere. And the MediaInfo object already has the customData attribute now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because others custom data informations maybe needed at the service level, that are not related to the mediaInfo object. Take the [load](https://developers.google.com/android/reference/com/google/android/gms/cast/RemoteMediaPlayer#load%28com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.cast.MediaInfo, boolean, long, long[], org.json.JSONObject%29) method from the chromecast framework for instance.


public void closeMedia(LaunchSession launchSession, ResponseListener<Object> listener);

/**
Expand Down
1 change: 1 addition & 0 deletions src/com/connectsdk/service/capability/WebAppLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public interface WebAppLauncher extends CapabilityMethods {
};

public WebAppLauncher getWebAppLauncher();
public String getWebAppId();
public CapabilityPriorityLevel getWebAppLauncherCapabilityLevel();

public void launchWebApp(String webAppId, LaunchListener listener);
Expand Down
13 changes: 11 additions & 2 deletions src/com/connectsdk/service/sessions/WebAppSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,17 @@ public void playMedia(String url, String mimeType, String title, String descript
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop,
MediaPlayer.LaunchListener listener) {
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, MediaPlayer.LaunchListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, MediaPlayer.LaunchListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
}

@Override
public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, long startPosition, Object customData, MediaPlayer.LaunchListener listener) {
Util.postError(listener, ServiceCommandError.notSupported());
}

Expand Down
12 changes: 12 additions & 0 deletions test/src/com/connectsdk/core/MediaInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import junit.framework.Assert;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
Expand Down Expand Up @@ -54,6 +56,14 @@ public void testMediaInfoBuilderWithAllParameters() {
String mimeType = "video/mp4";
String description = "description";
String iconUrl = "http://iconurl";
JSONObject customData = new JSONObject(){{
try {
put("data1", 1);
put("data2", 2);
} catch (JSONException e) {
e.printStackTrace();
}
}};

SubtitleInfo subtitle = new SubtitleInfo.Builder("").build();
String title = "title";
Expand All @@ -63,6 +73,7 @@ public void testMediaInfoBuilderWithAllParameters() {
.setIcon(iconUrl)
.setSubtitleInfo(subtitle)
.setTitle(title)
.setCustomData(customData)
.build();

Assert.assertEquals(url, mediaInfo.getUrl());
Expand All @@ -72,6 +83,7 @@ public void testMediaInfoBuilderWithAllParameters() {
Assert.assertEquals(1, mediaInfo.getImages().size());
Assert.assertEquals(subtitle, mediaInfo.getSubtitleInfo());
Assert.assertEquals(title, mediaInfo.getTitle());
Assert.assertEquals(customData, mediaInfo.getCustomData());
}

@Test
Expand Down
Loading