Developers who want to incorporate video recording, uploading, sharing, and playback in their mobile applications can use the YouTube platform to simplify their work and improve their final products. This article highlights some of the technologies that you might use in your applications.
The video recording process is performed using the underlying mobile platform. For example, your application could fire off a VIDEO_CAPTURE intent on Android:
Intent i = new Intent(); i.setAction(MediaStore.VIDEO_CAPTURE); startActivityForResult(i, CAPTURE_RETURN);
or launch the UIImagePickerController on iPhone iOS:
IImagePickerController *imagePicker = [[[UIImagePickerController alloc] init] autorelease]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; [self presentModalViewController:imagePicker animated:YES];
For more advanced recording options on iOS 4 and later you can also use the AVCaptureSession class from the AV Foundation Framework.
Your application can upload a video and its metadata to YouTube by sending an email to a special email address associated with the user’s YouTube account or by using one of three API methods: browser-based uploading, direct uploading or direct resumable uploading. For mobile applications, direct resumable uploading is the most reliable choice since it enables an application to gracefully recover from connectivity failures and resume an upload from the point of failure. YouTube’s resumable uploading protocol leverages the HTTP 1.1 Content-Range/Range mechanism to transfer videos in chunks and, in the event of an interruption, to identify the number of bytes that were successfully transferred.
While the actual video content is the most important component in an upload, video metadata is an integral part of the process since that metadata lets users locate videos in search and also enables other features described later in this article. In addition to common elements like a category, description, and title, mobile applications can easily include geolocation data from the phone’s GPS device. These data let you provide location-based search or to plot video locations on a map. For video upload applications seeking to minimize user interaction, zero-metadata uploads are another option and more information about that is available from this Google I/O talk.
The YouTube Data API also provides rich functionality for video sharing activities. Like other Google Data APIs, the YouTube API uses a REST-inspired protocol that supports Atom, JSON and JSON-C data representations. JSON-C’s compact API responses are a particularly good fit for mobile environments, which are frequently resource-constrained. The API exposes flexible video search functionality; the ability to comment on and rate videos; access to subscriptions, favorite videos, playlists, and a recommendation engine; and a host of community features that help you to integrate video into social applications.
All of these functions can be incorporated into a mobile application using programming language-specific client libraries, or by directly interacting with YouTube’s API servers over HTTP. The former approach abstracts most of the protocol complexity at the expense of a larger application footprint. The latter approach lets you hand-craft interactions with the specific API services that your application uses. In the end the choice is application-specific. To get started, see the Java GData library for Android or the Objective-C GData library for the iPhone. More complex mobile video applications may benefit from integration with a server back-end. One such application is YouTube Direct (Figure 1), which features Open Source server code pre-configured to run on Google App Engine, as well as reference client implementations of video upload for Android (ytd-android, shown in Figure 1) and iPhone (ytd-iphone).
Figure 1: YouTube Direct Android Application
Security and authentication are also important aspects of mobile YouTube application development. While some API operations are available to unauthenticated clients, other requests require authorization, which is done through an authentication token submitted in the API request. Such operations include video uploads as well as any other operations that modify or write data or that access private user information.
The API supports three authentication methods: AuthSub, OAuth and ClientLogin. ClientLogin is the simplest method to use for mobile applications and on Android AccountManager can be used to easily obtain authentication tokens. However, applications that integrate a mobile client and multiple web back-ends should consider using OAuth, which is preferred as an open standard, or AuthSub, which is Google-specific. See this application for a sample OAuth authentication implementation on Android, and GDataOAuthViewControllerTouch for a sample implementation on iPhone iOS.
And, finally, videos exist so that people can watch them. Again, the YouTube platform offers several options.
- Most modern mobile platforms come bundled with a YouTube player application, enabling quick integration. If your platform does not include a YouTube player application, you can download one. A mobile application launches a player using a platform service. For example, on Android, an application uses the ACTION_VIEW intent, and on iPhone an application can launch the player using
openURLmethod of the
UIApplicationclass as covered in this blog post.
- The YouTube mobile website, http://m.youtube.com, lets you easily integrate video playback in a web application.
- For finer control of the playback experience, applications on Adobe Flash-enabled platforms can extend the AS3 YouTube player, which offers higher quality playback.