2010-12-16 9 views
4

私はこのようなyoutubeアプリを作りたい(Youtube Stream)http://itunes.apple.com/us/app/youtube-stream/id384383425?mt=8# iphoneのyoutubeアプリを起動せずにいくつかの動画をYouTubeからストリーム/ダウンロードして同じアプリ内で再生するアプリ。 私はたくさん検索しましたが、どのようにそれを行うには手掛かりを見つける...任意の1つは、ソリューションを提案することができます...iphone:MPMoviePlayerを使用してアプリケーションでYouTube動画をストリーミング再生する方法は?

+0

Mohan、私は同じコードを探しています。あなたが何かを見つけたら教えてください。 – Biko

答えて

2

iphoneアプリの中でYouTubeビデオをストリーム/再生する方法を見つけましたが、私はリンゴがそれを認識するかyoutubeの言葉と条件で私はplzはチェックして、それがどのように動作するかと言う私の.hと.Mファイルを添付ベロー...

YoutubePlayerViewController.h

#import<UIKit/UIKit.h> 
#import<MediaPlayer/MediaPlayer.h> 

@interface YoutubePlayerViewController : UIViewController 
{ 
    UITextField *yurl; 
    NSMutableData *responseData; 
    NSString *cacheLink; 
    MPMoviePlayerController *moviePlayer; 

} 

@property(nonatomic,retain)IBOutlet UITextField *yurl; 
@property(nonatomic,retain)NSString *cacheLink; 

-(IBAction)Play:(id)sender; 
-(IBAction)removeKeyboard; 
@end 

enter image description here

// -------- -------------------------------------------------- ----------------------

//YouTubePlayerViewController.m

#import "YoutubePlayerViewController.h" 

@implementation YoutubePlayerViewController 
@synthesize yurl,cacheLink; 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSLog(@"view did load"); 
} 


-(IBAction)removeKeyboard 
{ 

    [yurl resignFirstResponder]; 

} 

-(IBAction)Play:(id)sender 
{ 

    //1.get the url 
    NSString *url=yurl.text; 
    //NSString *[email protected]"http://www.youtube.com/watch?v=t2o5MhaSWRs"; 
    //2.show loding view 

    //3.make http request 
    responseData = [[NSMutableData data] retain]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; 
    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 





    //3.parse jason string for itag=18 
    //5.create an NSURL with that string 
    //6.start the player with url 

} 



- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    NSLog(@"did receving response"); 
    [responseData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    //NSLog(@"receving data"); 
    [responseData appendData:data]; 

} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"Connection failed: %@", [error description]); 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"%d",responseData.length); 
    NSString* strServerResponse= [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding]; 

    NSLog(@"%@",strServerResponse); 
    NSLog(@"\n***********************************************\n"); 

    NSArray *temp=[strServerResponse componentsSeparatedByString:@"swfConfig"]; 
    strServerResponse=[temp objectAtIndex:1]; 

    temp=[strServerResponse componentsSeparatedByString:@".c.youtube.com,18|"]; 
    strServerResponse=[temp objectAtIndex:1]; 

    temp=[strServerResponse componentsSeparatedByString:@"||"]; 
    strServerResponse=[temp objectAtIndex:0]; 

    strServerResponse=[strServerResponse stringByReplacingOccurrencesOfString:@"\\" withString:@""]; 
    NSLog(@"%@",strServerResponse); 
    self.cacheLink=strServerResponse; 


    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"link" message:self.cacheLink delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 

    NSURL *url=[[NSURL alloc] initWithString:self.cacheLink]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    [self.view addSubview:moviePlayer.view]; 
    moviePlayer.view.frame = CGRectMake(5,150,310,230); 
    moviePlayer.view.backgroundColor=[UIColor blackColor]; 
    [moviePlayer play]; 

    [connection release]; 
}    


/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 
+0

mp4へのホットリンクを抽出する法的問題についてはどうですか?リーガルおよびアップルストアに準拠していますか? – cDima

1

それはここでは簡単 だが、私の例である:https://github.com/comonitos/youtube_video

私はそれはユーチューブのMP4動画のURLを取得し、ダウンロードするよりも、と見ることができますピーター・スタインバーガーによってPSYouTubeExtractor.hクラスを使用し、問題

NSURLConnection + NSNotificationCenter +ではありませんPSYouTubeExtractor + NSMutableData

+0

iPhoneでこの方法を試してみましたが、うまくいきました。 iPadでは再生できません。動画が再生され、動画の音が聞こえますが、YouTubeプレーヤーは表示されません。 – Amit

+0

@comonitos、@ amit please help ..このクラスを実装するには..czコードがシミュレータとデバイスの両方で動作していません – Bajaj

関連する問題