Play YouTube videos in iPhone app without using UIWebView?(在 iPhone 应用程序中播放 YouTube 视频而不使用 UIWebView?)
问题描述
我想通过我的 iPhone 应用播放 YouTube 视频.我必须尝试使用以下代码在我的 iPhone 应用中播放 YouTube 视频,
I want to play YouTube videos from my iPhone app. I have to tried play YouTube videos in my iPhone app with the following codes,
[self playVideo:@"http://www.youtube.com/watch?v=WL2l_Q1AR_Q" frame:CGRectMake(20, 70, 280, 250)];
- (void)playVideo:(NSString *)urlString frame:(CGRect)frame
{
NSString *embedHTML = @"
<html><head>
<style type="text/css">
body {
background-color: transparent;
color: white;
}
</style>
</head><body style="margin:0">
<embed id="yt" src="JUA=" type="application/x-shockwave-flash"
width="%0.0f" height="%0.0f"></embed>
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
NSLog(@"%@",html);
}
但是,这段代码对我不起作用.我也试过 MPMoviePlayerController
代码是,
But, this code is not working for me. And also i have tried with MPMoviePlayerController
the code is,
NSURL *fileURL = [NSURL URLWithString:@"http://www.youtube.com/watch?v=WL2l_Q1AR_Q"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
这对我也不起作用.谁能告诉我我在哪里做错并建议我任何想法?我想在 MPMoviewPlayerController
中播放 YouTube 视频,而不是使用 UIWebView
.提前致谢.
This is also not working for me. Can anyone please tell me where i did wrong and suggest me any ideas? I want to play the YouTube videos in MPMoviewPlayerController
rather than using UIWebView
. Thanks in advance.
推荐答案
Mr.Yuvaraj.M 你上面的代码是正确的.请在您的 iPhone/iPod touch 设备中运行该项目.youtube 视频可能不支持/无法在模拟器中使用.请检查一下.谢谢.
Mr.Yuvaraj.M your above code is correct. Please run the project in your iPhone/iPod touch device. The youtube videos may not support/not work in Simulator. Please check on this. Thanks.
这篇关于在 iPhone 应用程序中播放 YouTube 视频而不使用 UIWebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iPhone 应用程序中播放 YouTube 视频而不使用 UIWebView?
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- URL编码Swift iOS 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01