我想做一個youtube這樣的應用程序(Youtube Stream)http://itunes.apple.com/us/app/youtube-stream/id384383425?mt=8#爲iPhone的應用程序,其中一些視頻從YouTube上流式傳輸/下載並在沒有啓動iPhone的YouTube應用程序的同一應用程序中播放。 我搜索很多,找不到如何做it..can任何一個提出一個解決方案的線索......iphone:如何流和使用MPMoviePlayer在應用程序中播放的YouTube影片?
4
A
回答
2
我發現流/播放YouTube視頻的iPhone應用程序內的一種方式,但我不知道蘋果會認識到它或它的根據youttube術語和矛盾。婁我附上我的.h和.m文件PLZ檢查,並說,它是如何工作..
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
// -------- -------------------------------------------------- ----------------------
//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 2012-06-03 04:20:52
1
這很容易 這是我的例子:https://github.com/comonitos/youtube_video
我用PSYouTubeExtractor.h類由彼得·斯坦伯格它可以讓YouTube的MP4視頻網址,比下載和觀看是沒有問題的
NSURLConnection的+ NSNotificationCenter + PSYouTubeExtractor + NSMutableData
相關問題
- 1. 如何使用MPMoviePlayer播放YouTube視頻?
- 2. 如何在iPhone應用程序中播放YouTube視頻?
- 3. 如何在iPhone應用程序中播放電影?
- 4. 如何使用iphone sdk中的mpmovieplayer播放直播視頻?
- 5. MPMoviePlayerController反向播放電影(向後)在iPhone應用程序中不流暢iPhone
- 6. iPhone在應用程序的YouTube中播放
- 7. MPMoviePlayer加載和播放電影保存在應用程序文件
- 8. 在iphone應用中播放youtube視頻
- 9. 如何在C++應用程序中播放和播放Youtube/FLV視頻?
- 10. 在iPhone應用程序中播放youtube視頻
- 11. 在iPhone應用程序中從庫中播放電影
- 12. Objective-C的iPhone - 一個應用程序中播放的YouTube
- 13. 在iPhone應用程序中播放動畫電影
- 14. 如何在iPhone應用程序中錄製和播放聲音?
- 15. 如何使用YouTube Android Player API播放YouTube直播視頻流?
- 16. 在iPhone應用程序中播放YouTube視頻而不使用UIWebView?
- 17. 如何嵌入Youtube視頻和播客到iPhone應用程序
- 18. 在iphone應用程序中不播放RTSP實時流
- 19. 如何在C++應用程序中從Youtube播放FLV文件?
- 20. 如何在Silverlight應用程序中播放youtube視頻?
- 21. 在Mpmovieplayer或Mpmusicplayer播放youtube視頻ios
- 22. 使用MPMoviePlayer播放視頻
- 23. iPhone:如何讓音樂播放使用OpenAL的應用程序?
- 24. xamarin如何在youtube應用程序中從我的ios應用程序中通過按鈕播放youtube視頻
- 25. 如何在C#WinForm應用程序中播放電影
- 26. 如何在應用中播放電影?
- 27. 在使用Javascript的iPhone Web應用程序中播放聲音?
- 28. 使用Monotouch在iPhone中播放MJPEG流
- 29. 如何在UIView在iOS應用程序中播放視頻流?
- 30. 如何在Android應用程序中使用全屏播放YouTube視頻
磨憨,我在尋找相同的代碼。如果你發現任何東西,請告訴我。 – Biko 2011-02-21 14:02:57