问题
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.
回答1:
- 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
回答2:
You will have to load some sort of document to test your connection speed.
an example -- http://alexle.net/archives/257
来源:https://stackoverflow.com/questions/4185266/html5-video-for-iphone-ipad-how-to-detect-connection-speed