About Me

My photo
Santa Clarita, Ca, United States
I work as a Technology Manager in the Entertainment Industry. My first film was Disney's Dinosaur and have been credited on several films since. I love working on old electronics, especially old radios. I am also passionate about technology and education. I have 4 kids and you can read about us on our family blog.

Saturday, February 4, 2012

Uploading To YouTube From The iPhone

While working on an iPhone application, I wanted to add the ability to share videos on YouTube.  Since the iPhone comes with a YouTube application, I expected this to be pretty easy. What I found was that, although not terrible, there were more options for doing this than I expected. The choices you make depend on the amount of integration you want with your application.  If you are looking at a similar scenario, here are some options to consider.

1) Have Users Upload From A Photo Album
By far, the simplest way to upload a video to YouTube from your iPhone is to make use of the built-in "Send To YouTube" button in the photo albums. You can have your application save the movie to the phone, and then have the user share it from there.  Making your application save a movie to the phone is pretty easy and can be done with the following line of code.

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (pathToMovieFile))
{
    UISaveVideoAtPathToSavedPhotosAlbum (pathToMovieFile, nil, nil, nil);
}

Once the movie is saved, the user needs to share it from their album.   To do this, they click on the "Pictures" icon on the phone and go to "Camera Roll"





You can then browse to the video you want to upload.  When you find it, click on the "Send To YouTube Button". Your phone will guide you through uploading the video.


First, it asks you to log in to your YouTube account. Generally, this is a GMail account.


Once you enter your credentials, you are taken to a very nice page to enter information about your video and upload it. 


Once it is done, you'll get a confirmation that the movie uploaded. The nicest thing about all this is that you don't have to write any more code than what it took to create and save the movie file. The YouTube login dialog and details page all are handled by the phone.

2) EMail The Video To YouTube Mobile
YouTube has a nice feature that allows you to get an e-mail address that will publish videos for you. You simply send e-mail to this address, and it appears on your YouTube channel.  To do this, you need to be able to send your movie as an e-mail.  You could use the above example and simply use the "EMail Video" button. Though, if you wan to be a bit more deluxe, you could have your application spawn the e-mail message with the address already filled out.  Sending an e-mail from the phone is pretty straight forward using the MFMailComposeViewController class.  Rather than put all the code here, there is a great Apple Example you can reference.

Of course, you'll need to know the YouTube address for your user.  You get it from the YouTube web site under "Mobile Setup" in your account settings.  I could walk you through this, but it's easier to let YouTube explain in the following video.



3) Full You Tube Integration With Your Application
The most deluxe, and also the most difficult you can choose is to write code to  integrate YouTube into your application. For instance, you could have a "Share On YouTube" button in your application that walks the user through uploading their video.  This would provide the same experience as the first option, but do it entirely from within your application.  Essentially, you will need to implement all the code from Step #1 yourself in your application. This is considerably more work than the above options, but also provides the nicest experience for your user. 

Here is an example screen from our application.  We wanted the e-mail button to share the movie on e-mail, which also would provide YouTube sharing through the above options. We also added  a YouTube button which we wanted to give the same experience as option #1 above.  In this particular version, YouTube and Facebook were not complete yet, so they are marked as "Coming Soon".


If you want to go to this level of integration, you will need to download the Google Data API for Objective C. There is an SVN Command that will download the API code so you can use it from your project. Once you download the code, there is a YouTubeSample.xcodeproj that will help you get started.  There's a couple things you'll notice right away.

1) You'll need a Google Client ID for your application.  This can be obtained by going to the Google API's Dashboard.
2) You'll need a YouTube Developer Key for your application. This can be obtained from the YouTube Dashboard.

Once you have the above two things, you'll be able to run the Google/YouTube Sample that comes with the sample code. You can upload videos using multiple different YouTube/Google accounts. You can also view information about them.

The GDataAPI is going to give you some options on how you post your video and you are going to need to decide if you want to request these from your interface, or if you want to decide for the user.  Here is some Google example code that shows some of these options.

GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];

In our case, we wanted to control these things so we didnt' ask the user. Though, they have the ability to change these things later by logging in to YouTube.

[Posting Not Yet Complete - This project is still in progress.   I'll post more as I work this out]

No comments:

Post a Comment

If you would like to reach out to the author directly, please email mschnitt@gmail.com