如何重新设置高度&嵌入式播放器使用CSS的宽度? [英] How to re-set the height & width of embedded player using CSS?

查看:104
本文介绍了如何重新设置高度&嵌入式播放器使用CSS的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建几个CSS来管理UIWebView中嵌入式视频播放器的方向。并且这些CSS将工作根据设备的方向调整播放器的大小。

I want to create a couple of CSS to manage the orientation of embedded video player in UIWebView. And these CSS shall work to resize the player according to the device's orientation.

如何在我的iPhone应用程序中创建和添加CSS以使用我的iPhone / iPad执行以下代码?

How can I create and add a CSS in my iphone application to execute the following code with my iPhone/iPad?

    <link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css">  
    <link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css">

编辑

以下是我为嵌入视频所做的代码(* youTubePlayer是UIWebView的一个实例。)

Following is the code that I have done for embedded video.(*youTubePlayer is an instance of UIWebView.)

    NSString* embedHTML = @"<html><head><style=\"margin:0\" link rel=\"stylesheet\" media=\"all and (orientation:portrait)\" href=\"portrait.css\">"
    "<link rel=\"stylesheet\" media=\"all and (orientation:landscape)\" href=\"landscape.css\">"
    "</style></head>"
    "<body embed id=\"yt\" src=\"%@\"type=\"application/x-shockwave-flash\"></embed>"
    "</body></html>";
    NSString* html = [NSString stringWithFormat:embedHTML, url];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [youTubePlayer loadHTMLString:html baseURL:baseURL];

还添加了 landscape.css
body
{
width:1002;
height:768;
}

And also have added landscape.css body { width: 1002; height: 768; }

portrait.css
body
{
width:768;
height:1024;
}

portrait.css body { width: 768; height: 1024; }

即使它无法正常工作。

Even though it's not working properly. What is wrong with the code, please let me know.

推荐答案

最后,我到达了我的目的地,并解决了问题下面的代码。它的工作完美的YouTube视频,还设置了UIWebview的方向。以下代码的好处是,它不会在更改设备方向时重新启动视频。

Finally I have reached to my destination and sort out the problem by the following code. It's working perfect with youtube videos and also setting orientation of UIWebview. The benefit of the following code is, it won't re-start the video on the change of orientation of device.

    NSString* embedHTML = @"<html><head><link rel=\"stylesheet\" media=\"all and (orientation:portrait)\" href=\"portrait-ipad.css\"><link rel=\"stylesheet\" media=\"all and (orientation:landscape)\" href=\"landscape-ipad.css\"></head><body><iframe type=\"text/html\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe></body></html>";
    NSString *videoID = [url stringByReplacingOccurrencesOfString:@"http://www.youtube.com/watch?v=" withString:@""];
    videoID = [videoID stringByReplacingOccurrencesOfString:@"&feature=youtube_gdata" withString:@""];
    html = [NSString stringWithFormat:embedHTML, videoID];      
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [youTubePlayer loadHTMLString:html baseURL:baseURL];

(youTubePlayer是UIWebView的一个实例。)

(youTubePlayer is an instance of UIWebView.)

这篇关于如何重新设置高度&amp;嵌入式播放器使用CSS的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆