我想做一个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. 如何在iPhone应用程序中播放YouTube视频?
- 2. 如何在iPhone应用程序中播放电影?
- 3. 如何使用iphone sdk中的mpmovieplayer播放直播视频?
- 4. MPMoviePlayerController反向播放电影(向后)在iPhone应用程序中不流畅iPhone
- 5. MPMoviePlayer加载和播放电影保存在应用程序文件
- 6. iPhone在应用程序的YouTube中播放
- 7. 在iphone应用中播放youtube视频
- 8. 如何在C++应用程序中播放和播放Youtube/FLV视频?
- 9. 在iPhone应用程序中从库中播放电影
- 10. Objective-C的iPhone - 一个应用程序中播放的YouTube
- 11. 如何在iPhone应用程序中录制和播放声音?
- 12. 在iPhone应用程序中播放YouTube视频而不使用UIWebView?
- 13. 在Mpmovieplayer或Mpmusicplayer播放youtube视频ios
- 14. 如何嵌入Youtube视频和播客到iPhone应用程序
- 15. 如何在Silverlight应用程序中播放youtube视频?
- 16. 如何在C++应用程序中从Youtube播放FLV文件?
- 17. 在iphone应用程序中不播放RTSP实时流
- 18. 使用MPMoviePlayer播放视频
- 19. xamarin如何在youtube应用程序中从我的ios应用程序中通过按钮播放youtube视频
- 20. 如何在C#WinForm应用程序中播放电影
- 21. 如何在应用中播放电影?
- 22. iPhone:如何让音乐播放使用OpenAL的应用程序?
- 23. 在使用Javascript的iPhone Web应用程序中播放声音?
- 24. 使用Monotouch在iPhone中播放MJPEG流
- 25. 我如何在桌面应用程序中使用youtube chromeless播放器?
- 26. 如何在Android应用程序中使用全屏播放YouTube视频
- 27. 如何随着电影在iOS 8中使用Swift播放而旋转MPMoviePlayer?
- 28. 如何在Android应用程序上播放YouTube 360度视频?
- 29. Youtube影片dispalying在Shockwave播放器,而不是YouTube视频的
- 30. 如何在MPMoviePlayer播放过程中启用iPhone自动锁定功能?
磨憨,我在寻找相同的代码。如果你发现任何东西,请告诉我。 – Biko 2011-02-21 14:02:57