English 中文(简体)
调整关于方向改变的网络视图中的 Youtube 视频大小
原标题:Resize youtube video in web view on orientation change

我有一个不使用全屏的网络视图。 我将它设置为在网络视图区域播放视频的 Youtube 视频。 当我改变设备方向时, 视图会调整大小, 但内容不会。 如果我设置比例页面以适应网络视图的旗帜, 它会正确改变方向, 但视频的右侧和底部总是有白色空间, 不论方向如何 。

我怎样才能让视频填满网络视图, 并调整方向, 而不浪费版面。 或者我如何让视频像在iPhone上一样播放全屏( 这会是我一个可行的选择, 跳过布局问题 ) 。

问题回答

I read this tutorial and was able to solve the problem. http://webdesignerwall.com/tutorials/css-elastic-videos

基本上,您可以将包含项的大小设置为用于肖像的一件事和用于景观的一件事。

还设置对象嵌入代码,使高度宽度达到100%,而不是固定宽度。

这是我的 html :

<span class="youtube">
    <object type="application/x-shockwave-flash" id="ytPlayer" style="visibility: visible;" allowscriptaccess="always">
    </object>
</span>

这是我的笔记本

var ytswf = document.getElementById( ytPlayer );
var videoID =  Nky9omXFZD4 ;
ytswf.outerHTML = "<object height="100%" width="100%" type="application/x-shockwave-flash" data="http://www.youtube.com/v/" + videoID + "&amp;enablejsapi=1&amp;playerapiid=ytplayerObj&amp;rel=0&amp;fs=1&amp;autoplay=0&amp;egm=0" id="ytPlayer" style="visibility: visible;" ><param name="allowFullScreen" value="True" /><param name="allowScriptAccess" value="always" /></object>";

这是我的CS:

.youtube{width:432px; height:245px;}
@media only screen and (orientation:portrait)
{
   .youtube{width:702px; height:398px;}
}

我用下面的代码 它对我有用

    // css
    // You can add your own width and height values or insert this values using stringWithFormat
    NSString *css = @"<style type="text/css">
    .youtube{width:320px; height:363px;}
    @media only screen and (orientation:portrait) { 
    .youtube{width:320px; height:363px;}
    }
    
    @media only screen and (orientation:landscape) {
    .youtube{width:480px; height:203px;}
    }
    </style>
    ";

    // different format of urls for iOS 5 and iOS 6
    NSString *src = ([[[UIDevice currentDevice] systemVersion] compare:@"6" options:NSNumericSearch] == NSOrderedAscending)
    ? @"http://www.youtube.com/watch?v=%@?autoplay=1"        //  iOS  5
    : @"http://www.youtube.com/v/%@?autoplay=1";             //  iOS  6

    // inserting css in <head> and inserting src
    NSString *youTubeVideoHTML =  [NSString stringWithFormat:
                                   (@"<html><head>%@</head>
                                    <body style="margin:0">
                                    <embed class="youtube" id="yt" src="%@" type="application/x-shockwave-flash" 
                                    ></embed>
                                    </body></html>") , css , src  ];
    // setting YouTube video ID
    finalHtml = [NSString stringWithFormat: youTubeVideoHTML , videoID ];

    [self.webView loadHTMLString:finalHtml baseURL:nil];




相关问题
mysql - store embed codes (youtube, vimeo etc)

How best to store the html for embedding? the only ways I can think of are: take the embed html and add <?php echo $var1; ?> where the id s go then store it in the db and use Eval to execute ...

openURL and YouTube

Is there any way to open the YouTube app from my app, with a defined search query? If not, is there a way to just open YouTube, without playing any video? All I m finding is ways to play videos.

emulating iPhone video player behaviour

I need to debug a networking application which handles video downloaded by iPhone from Youtube. iPhone downloads chunks of video by requesting each time a different file range (by adding Content-Range ...

Uploading video using the YouTube API via Flash AS3

I m trying to work out how to upload videos to YouTube using the api from flash. There seems to be libraries available for doing this with php, ruby, java etc. but not AS3. Can anyone point me in the ...

Curl setting Content-Type incorrectly

I am running a curl operation on the command line and am having trouble forcing the header to set as XML. I use the -H option to force the Content-Type to be xml, however, once I run the command I can ...

热门标签