将 YouTube 视频嵌入到

编程入门 行业动态 更新时间:2024-10-13 06:17:12
本文介绍了将 YouTube 视频嵌入到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我通过在互联网上找到的片段嵌入了来自 YouTube 的视频,这是我使用的代码:

I've embedded a video from YouTube via a snippet I've found on the Internet, here is the code that I've used:

@interface FirstViewController (Private) - (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame; @end @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; [self embedYouTube:@"www.youtube/watch?v=l3Iwh5hqbyE" frame:CGRectMake(20, 20, 100, 100)]; } - (void)embedYouTube:(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]; } - (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

它编译正确,当我打开它时,我看到一个白框位置不正确,这是代码创建的.我有两个问题:

It compiles correctly and when I open it, I see a white box positioned incorrectly, which the code created. I have two questions regarding it:

  • 我怎么知道视频是否可以播放,它只是一个普通的白色框,模拟器是否可以播放来自 YouTube 的视频?

  • How do I know if the video will play, it is just a plain white box, does the simulator play videos from YouTube?

    如何定位这个框?

    推荐答案

    刚刚测试了你的代码,它在 iPhone 上运行良好,但 iOS 模拟器不支持 Youtube 视频,所以你需要一个真实的设备进行测试.

    Just tested your code, it works fine on an iPhone, Youtube videos are not supported on the iOS simulator though, so you'll need a real device for testing.

    如何定位这个框?

    您已经在这一行传递了盒子的 X (20)、Y(20)、宽度(100) 和高度(100):

    You are already passing the X (20), Y(20), width(100) and height(100) of the box at this line:

    [self embedYouTube:@"..." frame:CGRectMake(20, 20, 100, 100)];

    要在之后更改视图的位置,请修改其 center 属性:

    To change the position of the view afterwards, you modify its center property:

    videoView.center = CGPointMake(200, 100 );
  • 更多推荐

    将 YouTube 视频嵌入到

    本文发布于:2023-11-05 18:34:21,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1561552.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:视频   YouTube

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!