适用于iPhone / iPad的HTML5视频。如何检测连接速度? [英] HTML5 video for iPhone / iPad. How to detect connection speed?
问题描述
我需要在Safari for iPhone / iPad中以最佳质量流式传输视频。
我创建了2个视频文件:一个是低质量的慢速3G速度,一个在高质量的WiFi宽带流媒体。我注意到有些应用程序(例如YouTube)能够检测到移动设备是通过3G还是WiFi运行,因此请选择小尺寸的视频而不是高质量的视频。
现在这是我的DOM / Javascript代码, $ v 值被 PHP 替换,并包含视频文件名:
< video id =thevideosrc =streaming / video_<?= $ v?> ;.m4vwidth =600height =360 width =640height =360preload =preloadcontrols =controlsautoplay =autoplay>
flowplayer / video<?= $ v?> .m4v
< / video>
< script type =text / javascript>
var myvideo = document.getElementById(thevideo);
myvideo.load();
myvideo.play();
< / script>
我可以在Javascript / Webkit中编写能够检测连接模式的东西吗?
感谢所有。
- 我假设这将在你自己的应用程序中:你可以使用苹果的可达性在发送UIWebView的请求之前确定应用程序中的连接类型。您可以通过添加查询来修改请求的URL:
//通过可达性确定连接类型
myURLString = [myURLString stringByAppendingString:[NSString stringWithFormat:@?conntype =%@,* connTypeString]];
//然后发送页面的请求。
然后,在PHP中解析URL查询以确定应该使用的视频网址。
- 如果没有,您需要通过第三方Javascript或PHP脚本测试连接速度。
示例: http://jan.moesen.nu/code/php/speedtest/index.php?numKB=512
I need to stream a video in Safari for iPhone/iPad with the best possible quality.
I created 2 video files: one in low-quality for slow 3G speed, one in hi-quality for WiFi broadband streaming. I noticed that some apps (YouTube for example) are able to detect if the mobile device is running by 3G or WiFi, and so select a small sized video rather than an hi-quality video.
Now that is my DOM / Javascript code, the $v value is replaced by PHP and contains the video filename:
<video id="thevideo" src="streaming/video_<?=$v ?>.m4v" width="600" height="360" width="640" height="360" preload="preload" controls="controls" autoplay="autoplay"> flowplayer/video<?=$v ?>.m4v </video> <script type="text/javascript"> var myvideo = document.getElementById("thevideo"); myvideo.load(); myvideo.play(); </script>
Can I write something in Javascript / Webkit that is able to detect the connection mode?
Thanks to all.
解决方案- I am assuming this will be in your own application:
You could use Apple's Reachability to determine the connection type in your application before sending the UIWebView's request. You can modify the request's URL by adding a query:
//determine the connection type via Reachability myURLString = [myURLString stringByAppendingString:[NSString stringWithFormat:@"?conntype=%@", *connTypeString]]; //then send the request for the page.
Then, parse the URL query in PHP to determine the video URL that should be used.
- If not, you would need to test the connection speed via a third-party Javascript or PHP script.
Example: http://jan.moesen.nu/code/php/speedtest/index.php?numKB=512
这篇关于适用于iPhone / iPad的HTML5视频。如何检测连接速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!