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

Support passing customData to media load request #137

Open
wants to merge 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion src/main/java/su/litvak/chromecast/api/v2/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private void startSession(String destinationId) throws IOException {
}
}

public MediaStatus load(String destinationId, String sessionId, Media media, boolean autoplay, double currentTime, Map<String, String> customData) throws IOException {
public MediaStatus load(String destinationId, String sessionId, Media media, boolean autoplay, double currentTime, Object customData) throws IOException {
startSession(destinationId);
StandardResponse.MediaStatus status = sendStandard("urn:x-cast:com.google.cast.media", StandardRequest.load(sessionId, media, autoplay, currentTime, customData), destinationId);
return status == null || status.statuses.length == 0 ? null : status.statuses[0];
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/su/litvak/chromecast/api/v2/ChromeCast.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,10 @@ public final MediaStatus load(String url) throws IOException {
* @throws IOException
*/
public final MediaStatus load(String mediaTitle, String thumb, String url, String contentType) throws IOException {
Status status = getStatus();
Application runningApp = status.getRunningApp();
if (runningApp == null) {
throw new ChromeCastException("No application is running in ChromeCast");
}
Map<String, Object> metadata = new HashMap<String, Object>(2);
metadata.put("title", mediaTitle);
metadata.put("thumb", thumb);
return channel().load(getTransportId(runningApp), runningApp.sessionId, new Media(url,
return load(new Media(url,
contentType == null ? getContentType(url) : contentType, null, null, null,
metadata, null, null), true, 0d, null);
}
Expand All @@ -457,6 +452,25 @@ public final MediaStatus load(String mediaTitle, String thumb, String url, Strin
* @throws IOException
*/
public final MediaStatus load(final Media media) throws IOException {
return load(media, true, 0d, null);
}

/**
* <p>Loads and starts playing specified media</p>
*
* <p>If no application is running at the moment then exception is thrown.</p>
*
* @param media The media to load and play.
* See <a href="https://developers.google.com/cast/docs/reference/messages#Load">
* https://developers.google.com/cast/docs/reference/messages#Load</a> for more details.
* @param autoplay whether the media should start playing when loaded
* @param currentTime seconds since beginning of content
* @param customData Application-specific data
* @return The new media status that resulted from loading the media.
* @throws IOException
*/
public final MediaStatus load(final Media media, boolean autoplay, double currentTime,
Object customData) throws IOException {
Status status = getStatus();
Application runningApp = status.getRunningApp();
if (runningApp == null) {
Expand All @@ -469,7 +483,8 @@ public final MediaStatus load(final Media media) throws IOException {
} else {
mediaToPlay = media;
}
return channel().load(getTransportId(runningApp), runningApp.sessionId, mediaToPlay, true, 0d, null);
return channel().load(getTransportId(runningApp), runningApp.sessionId, mediaToPlay, autoplay, currentTime,
customData);
}

/**
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/su/litvak/chromecast/api/v2/StandardRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

/**
* Parent class for transport object representing messages sent TO ChromeCast device.
*/
Expand Down Expand Up @@ -91,17 +89,12 @@ static class Load extends StandardRequest {
@JsonProperty
final Object customData;

Load(String sessionId, Media media, boolean autoplay, double currentTime,
final Map<String, String> customData) {
Load(String sessionId, Media media, boolean autoplay, double currentTime, Object customData) {
this.sessionId = sessionId;
this.media = media;
this.autoplay = autoplay;
this.currentTime = currentTime;

this.customData = customData == null ? null : new Object() {
@JsonProperty
Map<String, String> payload = customData;
};
this.customData = customData;
}
}

Expand Down Expand Up @@ -180,7 +173,7 @@ static Stop stop(String sessionId) {
}

static Load load(String sessionId, Media media, boolean autoplay, double currentTime,
Map<String, String> customData) {
Object customData) {
return new Load(sessionId, media, autoplay, currentTime, customData);
}

Expand Down