WARNING : This content was auto generated from a backup file, links and images may be broken.

youtubeI have been plodding away on a project (it is getting there almost) and one of the things that I really wanted was to provide video tutorials for the user. I really do not want to package all these videos with the application really once you’ve watched them once you will probably never look at them again (If I’m wrong about that let me know ).

The new idea is to stream them down to the device once option was to use the MoviePlayer provided with the sdk. This is fine if you want to host your own video content but I’m not that confident that I would be able to provide a reliable content service. Whats the alternative then well there is always YouTube and the iPhone has a compatible way of playing back videos even inside the application. Unfortunately to play these YouTube videos you need to use a UIWebView where the simplest version of a player would present the user with a link to play the video. Not the most elegant solution but it works but I was not really happy with the solution.

I decided I could do better I really wanted a player that provided complete application integration and the resulting Player is just that. The player is easy to use and has simplest API I could come up with it is also very easy to integrate with any application. Go on and try it out.

//  YouTubePlayer.h
//  Created by Robert on 18/12/2009.

#import <Foundation/Foundation.h>

@interface YouTubePlayer : NSObject <UIWebViewDelegate UIAlertViewDelegate>
UIView  *  background;
UIWebView *  webView;
UIActivityIndicatorView * activityIndicator;

- (void) playbackVideo:(NSString*)_videoID InView:(UIView*)_view;

Example use:
// Inside a UIViewController
- (void) play
     // create the video player object
     if ( videoPlayer == nil )
           videoPlayer = [[YouTubePlayer alloc] init];

    // Request the video to be played using the video id
     [videoPlayer playbackVideo:@"MuU00Q3RhDg" InView:self.view];

As always the source is provided as is and use at your own risk also feel free to alter and use as you want I do not mind. Have Fun.

Download : YouTubePlayer.h YouTubePlayer.m

Note: You will need to include the SystemConfiguration framework as this is used to check for the availability of a web connection.

Thanks to the following resources that make it possible to build this player:


Comments powered by Disqus