Search in sources :

Example 1 with MediaPlayer

use of com.connectsdk.service.capability.MediaPlayer in project butter-android by butterproject.

the class WebOSTVService method playMedia.

@Override
public void playMedia(final String url, final String mimeType, final String title, final String description, final String iconSrc, final boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
    if ("4.0.0".equalsIgnoreCase(this.serviceDescription.getVersion())) {
        DeviceService dlnaService = this.getDLNAService();
        if (dlnaService != null) {
            MediaPlayer mediaPlayer = dlnaService.getAPI(MediaPlayer.class);
            if (mediaPlayer != null) {
                mediaPlayer.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
                return;
            }
        }
        JSONObject params = null;
        try {
            params = new JSONObject() {

                {
                    put("target", url);
                    put("title", title == null ? NULL : title);
                    put("description", description == null ? NULL : description);
                    put("mimeType", mimeType == null ? NULL : mimeType);
                    put("iconSrc", iconSrc == null ? NULL : iconSrc);
                    put("loop", shouldLoop);
                }
            };
        } catch (JSONException ex) {
            ex.printStackTrace();
            Util.postError(listener, new ServiceCommandError(-1, ex.getLocalizedMessage(), ex));
        }
        if (params != null)
            this.displayMedia(params, listener);
    } else {
        final WebAppSession.LaunchListener webAppLaunchListener = new WebAppSession.LaunchListener() {

            @Override
            public void onError(ServiceCommandError error) {
                listener.onError(error);
            }

            @Override
            public void onSuccess(WebAppSession webAppSession) {
                webAppSession.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
            }
        };
        this.getWebAppLauncher().joinWebApp(MEDIA_PLAYER_ID, new WebAppSession.LaunchListener() {

            @Override
            public void onError(ServiceCommandError error) {
                getWebAppLauncher().launchWebApp(MEDIA_PLAYER_ID, webAppLaunchListener);
            }

            @Override
            public void onSuccess(WebAppSession webAppSession) {
                webAppSession.playMedia(url, mimeType, title, description, iconSrc, shouldLoop, listener);
            }
        });
    }
}
Also used : JSONObject(org.json.JSONObject) WebAppSession(com.connectsdk.service.sessions.WebAppSession) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) MediaPlayer(com.connectsdk.service.capability.MediaPlayer)

Example 2 with MediaPlayer

use of com.connectsdk.service.capability.MediaPlayer in project butter-android by butterproject.

the class WebOSTVService method displayImage.

@Override
public void displayImage(final String url, final String mimeType, final String title, final String description, final String iconSrc, final MediaPlayer.LaunchListener listener) {
    if ("4.0.0".equalsIgnoreCase(this.serviceDescription.getVersion())) {
        DeviceService dlnaService = this.getDLNAService();
        if (dlnaService != null) {
            MediaPlayer mediaPlayer = dlnaService.getAPI(MediaPlayer.class);
            if (mediaPlayer != null) {
                mediaPlayer.displayImage(url, mimeType, title, description, iconSrc, listener);
                return;
            }
        }
        JSONObject params = null;
        try {
            params = new JSONObject() {

                {
                    put("target", url);
                    put("title", title == null ? NULL : title);
                    put("description", description == null ? NULL : description);
                    put("mimeType", mimeType == null ? NULL : mimeType);
                    put("iconSrc", iconSrc == null ? NULL : iconSrc);
                }
            };
        } catch (JSONException ex) {
            ex.printStackTrace();
            Util.postError(listener, new ServiceCommandError(-1, ex.getLocalizedMessage(), ex));
        }
        if (params != null)
            this.displayMedia(params, listener);
    } else {
        final WebAppSession.LaunchListener webAppLaunchListener = new WebAppSession.LaunchListener() {

            @Override
            public void onError(ServiceCommandError error) {
                listener.onError(error);
            }

            @Override
            public void onSuccess(WebAppSession webAppSession) {
                webAppSession.displayImage(url, mimeType, title, description, iconSrc, listener);
            }
        };
        this.getWebAppLauncher().joinWebApp(MEDIA_PLAYER_ID, new WebAppSession.LaunchListener() {

            @Override
            public void onError(ServiceCommandError error) {
                getWebAppLauncher().launchWebApp(MEDIA_PLAYER_ID, webAppLaunchListener);
            }

            @Override
            public void onSuccess(WebAppSession webAppSession) {
                webAppSession.displayImage(url, mimeType, title, description, iconSrc, listener);
            }
        });
    }
}
Also used : JSONObject(org.json.JSONObject) WebAppSession(com.connectsdk.service.sessions.WebAppSession) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) MediaPlayer(com.connectsdk.service.capability.MediaPlayer)

Aggregations

MediaPlayer (com.connectsdk.service.capability.MediaPlayer)2 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)2 WebAppSession (com.connectsdk.service.sessions.WebAppSession)2 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2