所以我在我的网站上提供H.264 .mp4视频.我正在使用开源HTML5视频播放器http://mediaelementjs.com/.一些访问者正在从Safari for iPhone查看.iPhone 4仅支持高达720p的视频播放,因此如果我将视频设置为小于此值,则可以使用4和4S.但4S支持高达1080p的视频.那么我如何为4S提供更大的视频,为4提供更小的视频呢?我试过这个:
<video width="640" height="400" id="player" controls="controls" preload="auto">
<source src="https://s3.amazonaws.com/my-big-1080p-video.mp4" type="video/mp4">
<source src="https://s3.amazonaws.com/my-small-720p-video.mp4" type="video/mp4">
</video>
Run Code Online (Sandbox Code Playgroud)
但它没有用.iPhone 4不够智能,无法尝试第二个来源.如何让我的网站为不同的设备提供正确的视频?
我使用UIWebView的是以HTML字符串的形式显示内容 - 不是网站,高于iPhone的屏幕,而不需要滚动webView本身,将其留给父滚动视图.
为了实现这一点,我需要一种方法来获取总文档大小,包括可滚动区域,以设置webView的高度.我尝试了许多不同的Javascript解决方案:
(document.height !== undefined) ? document.height : document.body.offsetHeight // Returns height of UIWebView
document.body.offsetHeight // Returns zero
document.body.clientHeight // Returns zero
document.documentElement.clientHeight // Returns height of UIWebView
window.innerHeight // Returns height of UIWebView -2
document.body.scrollHeight // Returns zero
Run Code Online (Sandbox Code Playgroud)
有没有真正有效的解决方案?
当前(非工作)代码:
[[[self.singlePost.contentText subviews] lastObject] setScrollEnabled:NO];
int content_height = [[self.singlePost.contentText stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] intValue];
NSLog(@"Content_height: %d", content_height);
CGRect rect = self.singlePost.contentText.frame;
rect.size.height = content_height;
self.singlePost.contentText.frame = rect;
Run Code Online (Sandbox Code Playgroud)