开发者

What is the best way of providing videos on the web that also work on iPhone/iPad?

开发者 https://www.devze.com 2023-02-13 17:39 出处:网络
Is there a common way to implement videos on the web that will also work on iPhone/iPad? My idea is to p开发者_StackOverflow社区rovide two versions (Flash and HTML5) and check with JavaScript if HTML

Is there a common way to implement videos on the web that will also work on iPhone/iPad?

My idea is to p开发者_StackOverflow社区rovide two versions (Flash and HTML5) and check with JavaScript if HTML5 is supported — if so, then play Flash; if not, play HTML5. Maybe there’s a better way?


Dive into HTML5 nails it here : http://diveintohtml5.ep.io/video.html

The final markup uses a element for HTML5 video, a nested element for Flash fallback, and a small bit of script for the benefit of Android devices:

<video id="movie" width="320" height="240" preload controls>
  <source src="pr6.webm" type='video/webm; codecs="vp8, vorbis"' />
  <source src="pr6.ogv" type='video/ogg; codecs="theora, vorbis"' />
  <source src="pr6.mp4" />
  <object width="320" height="240" type="application/x-shockwave-flash"
    data="flowplayer-3.2.1.swf"> 
    <param name="movie" value="flowplayer-3.2.1.swf" /> 
    <param name="allowfullscreen" value="true" /> 
    <param name="flashvars" value='config={"clip": {"url": "http://wearehugh.com/dih5/pr6.mp4", "autoPlay":false, "autoBuffering":true}}' /> 
    <p>Download video as <a href="pr6.mp4">MP4</a>, <a href="pr6.webm">WebM</a>, or <a href="pr6.ogv">Ogg</a>.</p> 
  </object>
</video>
<script>
  var v = document.getElementById("movie");
  v.onclick = function() {
    if (v.paused) {
      v.play();
    } else {
      v.pause();
    }
  };
</script>


You can use HTML5 video tag as a default option and put a fallback object tag inside it.

You can read about HTML5 video tag usage in Safari (including Mobile Safari) here: https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Introduction/Introduction.html


You can present videos either from your app's resource bundle or streamed via the internet, using this class: MPMoviePlayerController

Apple docs:

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html


I found this to be very helpful:

http://camendesign.com/code/video_for_everybody

It uses HTML5 but gracefully fails to flash.

0

精彩评论

暂无评论...
验证码 换一张
取 消