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="%@" 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?
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01