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 new ConnectSDK MediaPlayer capability methods #24

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public void onRouteAdded(MediaRouter router, RouteInfo route) {
foundServices.put(uuid, foundService);

if (listUpdateFlag) {
for (DiscoveryProviderListener listenter: serviceListeners) {
listenter.onServiceAdded(CastDiscoveryProvider.this, foundService);
for (DiscoveryProviderListener listener: serviceListeners) {
listener.onServiceAdded(CastDiscoveryProvider.this, foundService);
}
}
}
Expand Down Expand Up @@ -243,8 +243,8 @@ public void onRouteChanged(MediaRouter router, RouteInfo route) {
foundServices.put(uuid, foundService);

if (listUpdateFlag) {
for (DiscoveryProviderListener listenter: serviceListeners) {
listenter.onServiceAdded(CastDiscoveryProvider.this, foundService);
for (DiscoveryProviderListener listener: serviceListeners) {
listener.onServiceAdded(CastDiscoveryProvider.this, foundService);
}
}
}
Expand Down
73 changes: 50 additions & 23 deletions src/com/connectsdk/service/CastService.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ public CastService(ServiceDescription serviceDescription, ServiceConfig serviceC
mWaitingForReconnect = false;
}

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

@Override
public String getServiceName() {
return ID;
Expand Down Expand Up @@ -688,8 +693,7 @@ public void displayImage(MediaInfo mediaInfo, LaunchListener listener) {
}

private void playMedia(String url, SubtitleInfo subtitleInfo, String mimeType, String title,
String description, String iconSrc, boolean shouldLoop,
LaunchListener listener) {
String description, String iconSrc, boolean shouldLoop, long startPosition, JSONObject customData, LaunchListener listener) {
MediaMetadata mMediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
mMediaMetadata.putString(MediaMetadata.KEY_TITLE, title);
mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, description);
Expand Down Expand Up @@ -722,18 +726,29 @@ private void playMedia(String url, SubtitleInfo subtitleInfo, String mimeType, S
.setMediaTracks(mediaTracks)
.build();

playMedia(mediaInformation, applicationID, listener);
//playMedia(mediaInformation, applicationID, listener);
playMedia(mediaInformation, applicationID, startPosition, customData, listener);
}

@Override
public void playMedia(String url, String mimeType, String title,
String description, String iconSrc, boolean shouldLoop,
LaunchListener listener) {
playMedia(url, null, mimeType, title, description, iconSrc, shouldLoop, listener);
playMedia(url, null, mimeType, title, description, iconSrc, shouldLoop, 0, null, listener);
}

@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(final MediaInfo mediaInfo, final boolean shouldLoop, long startPosition, Object customData, final LaunchListener listener) {
try {
mCastClient.getApplicationStatus(mApiClient);
} catch (CastClientException e) {
Expand All @@ -759,31 +774,40 @@ public void playMedia(MediaInfo mediaInfo, boolean shouldLoop, LaunchListener li
}
}

playMedia(mediaUrl, subtitle, mimeType, title, desc, iconSrc, shouldLoop, listener);
if(customData instanceof JSONObject) {
playMedia(mediaUrl, subtitle, mimeType, title, desc, iconSrc, shouldLoop, startPosition, (JSONObject)customData, listener);
}else{
playMedia(mediaUrl, subtitle, mimeType, title, desc, iconSrc, shouldLoop, startPosition, null, listener);
}

}

private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final LaunchListener listener) {
playMedia(mediaInformation, mediaAppId, 0, null, listener);
}

private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final long startPosition, final JSONObject customData, final LaunchListener listener) {
final ApplicationConnectionResultCallback webAppLaunchCallback =
new ApplicationConnectionResultCallback(new LaunchWebAppListener() {

@Override
public void onSuccess(final WebAppSession webAppSession) {
ConnectionListener connectionListener = new ConnectionListener() {

@Override
public void onConnected() {
loadMedia(mediaInformation, webAppSession, listener);
}
};
public void onSuccess(final WebAppSession webAppSession) {
ConnectionListener connectionListener = new ConnectionListener() {

runCommand(connectionListener);
}
@Override
public void onConnected() {
loadMedia(mediaInformation, startPosition, customData, webAppSession, listener);
}
};

@Override
public void onFailure(ServiceCommandError error) {
Util.postError(listener, error);
}
});
runCommand(connectionListener);
}

@Override
public void onFailure(ServiceCommandError error) {
Util.postError(listener, error);
}
});

launchingAppId = mediaAppId;

Expand All @@ -810,10 +834,13 @@ public void onConnected() {
runCommand(connectionListener);
}

private void loadMedia(com.google.android.gms.cast.MediaInfo mediaInformation,
final WebAppSession webAppSession, final LaunchListener listener) {
private void loadMedia(com.google.android.gms.cast.MediaInfo mediaInformation, final WebAppSession webAppSession, final LaunchListener listener) {
loadMedia(mediaInformation, 0, null, webAppSession, listener);
}

private void loadMedia(com.google.android.gms.cast.MediaInfo mediaInformation, long startPosition, JSONObject customData, final WebAppSession webAppSession, final LaunchListener listener) {
try {
mMediaPlayer.load(mApiClient, mediaInformation, true).setResultCallback(new ResultCallback<MediaChannelResult>() {
mMediaPlayer.load(mApiClient, mediaInformation, true, startPosition, customData).setResultCallback(new ResultCallback<MediaChannelResult>() {

@Override
public void onResult(MediaChannelResult result) {
Expand Down
3 changes: 2 additions & 1 deletion test/src/com/connectsdk/service/CastServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import junit.framework.Assert;

import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -493,7 +494,7 @@ private com.google.android.gms.cast.MediaInfo verifyPlayMedia(MediaInfo mediaInf
// loadMedia
ArgumentCaptor<com.google.android.gms.cast.MediaInfo> argMedia =
ArgumentCaptor.forClass(com.google.android.gms.cast.MediaInfo.class);
Mockito.verify(mediaPlayer).load(Mockito.same(googleApiClient), argMedia.capture(), Mockito.eq(true));
Mockito.verify(mediaPlayer).load(Mockito.same(googleApiClient), argMedia.capture(), Mockito.eq(true), Mockito.eq((long) 0), Mockito.eq((JSONObject) null));
return argMedia.getValue();
}

Expand Down