【问题标题】:How to re-set the height & width of embedded player using CSS?如何使用 CSS 重新设置嵌入式播放器的高度和宽度?
【发布时间】:2011-08-03 04:47:35
【问题描述】:

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

如何在我的 iphone 应用程序中创建和添加 CSS 以在我的 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 的一个实例。)

    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 身体 { 宽度:1002; 身高:768; }

portrait.css 身体 { 宽度:768; 身高:1024; }

即使它不能正常工作。代码有什么问题,请告诉我。

【问题讨论】:

    标签: iphone html css ipad


    【解决方案1】:

    终于到了目的地,通过下面的代码解决了问题。它与 youtube 视频完美搭配,还可以设置 UIWebview 的方向。以下代码的好处是,它不会在设备方向改变时重新启动视频。

        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 的一个实例。)

    【讨论】:

      【解决方案2】:

      您只是在宽度和高度之后缺少 px 吗?例如 Portrait.css body { 宽度:768px;高度:1024px; } 而不是 Portrait.css body { width: 768;身高:1024; }

      【讨论】:

      • 'px' 对实现css效果没有影响。
      猜你喜欢
      • 1970-01-01
      • 2012-07-24
      • 2015-08-01
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 2012-04-14
      • 2012-05-26
      • 2011-08-24
      相关资源
      最近更新 更多