This document describes the Brightcove App SDK for iOS, which enables you to develop your own iPhone native application to deliver your Brightcove videos to the iPhone, iPad, and other iOS platforms. In addition to this "getting started" article, check out these other documents:
The Brightcove App SDK for iOS is a Cocoa/Objective-C Library for employing the Brightcove Media API and for playing videos in a custom Brightcove movie player on Apple iOS devices like the iPhone, iPad, and iPod Touch. The Media API provides a Cocoa/Objective-C interface for the Brightcove video and playlist APIs. The player component adds support for email and Twitter sharing, and related and popular video overlays to the standard iOS video player.
With the expansion of the iTunes App Store and the iPhone platform, the demand for mobile media continues to grow. Using this SDK to create a native iOS application will help you create a unique experience for viewers. Access to your video content and metadata is easily retrieved using the SDK so you can tailor your app for viewers on the go and keep your brand visible and close to your audience at all times.
If you are considering building an iOS application, it's never too early to start preparing your video content for mobile delivery. Read more about encoding video for mobile delivery. You may also want to consider building a mobile web application; read more about how Brightcove can help.
The Brightcove App SDK for iOS requires that you have Apple iOS SDK version 3.1 or higher (support includes the latest version, iOS 4.1).
Watch this space for an update to the sample application that uses the latest enhancements to our SDK!
We used the 2.x version of the Brightcove App SDK for iOS to develop a sample application named OnePlanet. You can read about how we developed OnePlanet and you can watch a video about it:
You can also get this free iPhone app in the iTunes App Store.
To install the Brightcove App SDK for iOS:
-all_load -ObjC
If any of those frameworks are missing, right-click on the Frameworks group in Xcode, select "Add" and "Existing Frameworks..." to open a file browser that will allow you to select and add the frameworks to your project. NOTE: If you want to use only the Brightcove Media APIs and not the Brightcove iPhone video player, you do not need to include MediaPlayer.framework.
The BCMediaAPI class is a facade for all Brightcove Media API calls. This enables developers to instantiate it once for any needed calls:
BCMediaAPI *bc = [[BCMediaAPI alloc] initWithReadToken:@"MyApiKey"];
Invocations are handled using Cocoa-style error pointers; thus, the pattern for all invocations is as follows:
// Don't forget to include this line in your source (uncommented):
// #import "BCMediaAPI.h"
BCMediaAPI *bc = [[BCMediaAPI alloc] initWithReadToken:@"MyApiKey"];
NSError *err;
BCVideo *video = [bc findVideoById:1234 error:&err];
if (!video) {
// if the result is nil, and we sent the optional error argument,
// then the error will be populated by all underlying errors reported
// by the Brightcove server. We can use the following convenience method
// to dump the NSError's userInfo, where the underlying errors are reported,
// into an NSString for logging or other purposes:
NSString *errStr = [bc getErrorsAsString:err];
NSLog(errStr);
}
The BCMoviePlayerController class inherits from the Apple MPMoviePlayerController class. This is done to give you more control over how your video player is displayed and exposes the increased functionality that Apple has given developers. We are moving away from the fullscreen only experience that didn't give developers the control they need over the playback experience. The BCMoviePlayerController injects things like extracting the correct url to play back into the MPMoviePlayerController classes flow. The Brightcove specific methods exposed are setContentURL:(BCVideo *) video, searchForRenditionsBetweenLowBitRate:(int) lowBitRate andHighBitRate:(int) highBitRate and initWithContentURL:(BCVideo *) video searchForRenditionWithLowBitRate:(NSNumber *) lowBitRate andHighBitRate:(NSNumber *)highBitRate . These port over the major parts of the BCPlayer class that deal with video playback. To make sure the Brightcove code interacts with the MPMoviePlayerController correctly you need to follow one of the following flows.
This flow is best used when you are targeting iOS 3.2 currently only on the iPad and iOS 4 currently only on the iPhone (3G, 3GS & 4). Linked Library Type setting is Required.
Create the object with the init method and not any other convenience methods.
BCMoviePlayerController *player = [[BCMoviePlayerController alloc] init];
If you want to use the searchForRenditionsBetweenLowBitRate:andHighBitRate: method you have to call it before you set the content.
[player searchForRenditionsBetweenLowBitRate:[NSNumber numberWithInt:200000] andHighBitRate:[NSNumber numberWithInt:300000]];
Finally you set the content, this can be done before or after you have added the player to a view.
[player setContentURL:myVideo];
This flow allows you to develop code that will run on 3.1 and greater with out using any runtime checking to see what OS version you are running. Linked Library setting is Weak.
Create the object with the initWithContentURL: searchForRenditionWithLowBitRate: andHighBitRate: method. If you do not want to change the default bit-rates that we search for 200000 - 500000 you can pass nil for the last two params.
BCMoviePlayerController *player = [[BCMoviePlayerController alloc] initWithContentURL:self.video searchForRenditionWithLowBitRate:[NSNumber numberWithInt:200000] andHighBitRate:[NSNumber numberWithInt:300000]]; Call the play method to start playback
[player play];
// Don't forget to include this line in your source:
#import "BCMoviePlayerController.h"
BCMoviePlayerController *player = [[BCMoviePlayerController alloc] init];
[player setContentURL:self.video]; // video fetched via the media apis, type is BCVideo
CGRect rect = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
UIView *pView = player.view;
[pView setFrame:rect];
[self.view addSubview:player.view];
If you need help or have a question, please visit our forums. You can also follow the Brightcove App SDK for iOS on Twitter: http://twitter.com/bciphonesdk or register for updates and announcements about our mobile SDKs..