适用于iPhone / iPad的HTML5video。 如何检测连接速度?

我需要以最佳质量在Safari浏览器中传输video。

我创build了两个video文件:一个是低速的3G速度,一个是高质量的WiFi宽带stream。 我注意到一些应用程序(例如YouTube)能够检测到移动设备是通过3G还是WiFi运行,所以select一个小尺寸的video而不是高质量的video。

现在,这是我的DOM / Javascript代码, $ v值被replace为PHP,并包含video文件名:

<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> 

我可以用Javascript / Webkit写一些能够检测连接模式的东西吗?

谢谢大家。

  • 我假设这将在你自己的应用程序中:

在发送UIWebView请求之前,可以使用Apple的Reachability来确定应用程序中的连接types。 您可以通过添加查询来修改请求的URL:

 //determine the connection type via Reachability myURLString = [myURLString stringByAppendingString:[NSString stringWithFormat:@"?conntype=%@", *connTypeString]]; //then send the request for the page. 

然后,parsingPHP中的URL查询来确定应该使用的videoURL。

  • 如果没有,您需要通过第三方的Javascript或PHP脚本testing连接速度。

例如: http : //jan.moesen.nu/code/php/speedtest/index.php?numKB=512

你将不得不加载某种文件来testing你的连接速度。

一个例子 – http://alexle.net/archives/257