Beam Media

A common use case with Connect SDK is 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 assumes that you have discovered and connected to a device.

Beam an image file

NSURL *mediaURL = [NSURL URLWithString:@"http://www.connectsdk.com/files/9613/9656/8539/test_image.jpg"]; // credit: Blender Foundation/CC By 3.0
NSURL *iconURL = [NSURL URLWithString:@"http://www.connectsdk.com/files/2013/9656/8845/test_image_icon.jpg"]; // credit: sintel-durian.deviantart.com
NSString *title = @"Sintel Character Design";
NSString *description = @"Blender Open Movie Project";
NSString *mimeType = @"image/jpeg";

LaunchSession *_launchSession;
id<MediaControl> _mediaControl;

[_device.mediaPlayer displayImage:mediaURL
                          iconURL:iconURL
                            title:title
                      description:description
                         mimeType:mimeType
                          success:^(LaunchSession *launchSession, id<MediaControl> mediaControl) {
                              NSLog(@"display photo success");

                              // save these object references to control media playback
                              _launchSession = launchSession;
                              _mediaControl = mediaControl;

                              // you will want to enable your media control UI elements here
                          }
                          failure:^(NSError *error) {
                              NSLog(@"display photo failure: %@", error.localizedDescription);
                          }];

Beam an audio/video file

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

LaunchSession *_launchSession;
id<MediaControl> _mediaControl;

[_device.mediaPlayer playMedia:mediaURL
                       iconURL:iconURL
                         title:title
                   description:description
                      mimeType:mimeType
                       success:^(LaunchSession *launchSession, id<MediaControl> mediaControl) {
                           NSLog(@"play video success");

                           // save these object references to control media playback
                           _launchSession = launchSession;
                           _mediaControl = mediaControl;

                           // you will want to enable your media control UI elements here
                       }
                       failure:^(NSError *error) {
                           NSLog(@"play video failure: %@", error.localizedDescription);
                       }];

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
[_mediaControl pauseWithSuccess:nil failure:nil];

// play media file
[_mediaControl playWithSuccess:nil failure:nil];

// seek to 10 seconds
[_mediaControl seek:10 success:nil failure:nil];

// close media file
[_launchSession closeWithSuccess:nil failure:nil];
// or
[_device.mediaPlayer closeMedia:_launchSession success:nil failure:nil];

A Note on AirPlay Support

For beaming media to AirPlay devices, you must set the AirPlayServiceMode to AirPlayServiceModeMedia. See the API docs for more information.