Beam Media

A common use case with Connect SDK will be to beam a simple media file (image, video, audio) to a TV. The following is a quick example of how you can beam an image onto a TV. This example is assuming that you have discovered & connected to a device.

Beam an image file

public void showImageString mediaURL = "http://www.connectsdk.com/files/9613/9656/8539/test_image.jpg"; // credit: Blender Foundation/CC By 3.0
String iconURL = "http://www.connectsdk.com/files/2013/9656/8845/test_image_icon.jpg"; // credit: sintel-durian.deviantart.com
String title = "Sintel Character Design";
String description = "Blender Open Movie Project";
String mimeType = "image/jpeg";

LaunchSession mLaunchSession;
MediaControl mMediaControl;

MediaPlayer.LaunchListener listener = new MediaPlayer.launchListener() {
    @Override
    public void onSuccess(MediaLaunchObject object) {
        // save these object references to control media playback
        mlaunchSession = object.launchSession;
        mMediaControl = object.mediaControl;

        // you will want to enable your media control UI elements here
    }

    @Override
    public void onError(ServiceCommandError error) {
        Log.d("App Tag", "Display photo failure: " + error);
    }
}

mDevice.getMediaPlayer().displayImage( mediaURL iconURL title description mimeType listener);

Beam an audio/video file

public void showImageString mediaURL = "http://www.connectsdk.com/files/8913/9657/0225/test_video.mp4"; // credit: Blender Foundation/CC By 3.0
String iconURL = "http://www.connectsdk.com/files/7313/9657/0225/test_video_icon.jpg"; // credit: sintel-durian.deviantart.com
String title = "Sintel Trailer";
String description = "Blender Open Movie Project";
String mimeType = "video/mp4"; // audio/* for audio files

LaunchSession mLaunchSession;
MediaControl mMediaControl;

MediaPlayer.LaunchListener listener = new MediaPalyer.launchListener() {
    @Override
    public void onSuccess(MediaLaunchObject object) {
        // save these object references to control media playback
        mlaunchSession = object.launchSession;
        mMediaControl = object.mediaControl;

        // you will want to enable your media control UI elements here
    }

    @Override
    public void onError(ServiceCommandError error) {
        Log.d("App Tag", "Display photo failure: " + error);
    }
}

mDevice.getMediaPlayer().displayImage( mediaURL iconURL title description mimeType listener);

Control media playback

In the previous example, you will notice that the success block was called with a mediaControl object. In order to control the media in the current playback session, you will need to store a reference to this mediaControl object and call control methods on that object.

// pause media file
mMediaControl.pause(null);

// play media file
mMediaControl.play(null);

// seek to 10 seconds
mMediaControl(10, null);

// close media file
mMediaControl.close(null);
// or
mDevice.getMediaPlayer.closeMedia(mLaunchSession, null);