`
flex_莫冲
  • 浏览: 1099516 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

video element in ipad safari

 
阅读更多
video元素在ipad safari上的一些API是无法支持的。比如通过JS代码控制全屏。
我的要求是,页面上只有一个按钮,看不到视频元素,点击该按钮,全屏显示并播放视频,退出视频全屏后也是看不到视频元素的。

那么首先video元素是隐藏的。$(video).css({'visibility' : 'hidden', 'display' : 'none'});
按钮元素的 HTML
<div id="video2_context" style="z-index:1;position:absolute;width:200px;height:200px;left:50px;top:0px;"><img src="../images/多狀態 37_狀態 2 2_Content_P.png"></div>


video元素的HTML
<video id="video2" class="video" style="position: absolute; z-index: 1; left: 50px; top: 50px; visibility: hidden; display: none;" autobuffer="true" preload="auto" controls="controls" width="200" height="200" poster="../images/oceans-clip.png" __idm_id__="-1055178750"><source src="../videos/oceans-clip.mp4" type="video/mp4"><source src="../videos/oceans-clip.webm" type="video/webm"></video>


按钮的事件。注意必须通过jquery的get()函数去调用全屏 API才能实现。
$("#video2_context").bind("click",function(){
            	var enableFullScreen = video.webkitSupportsFullscreen;
            	var mozFull = video.mozfullscreenchange;
            	if (enableFullScreen) {
            		$(video).show();
            		//video.load();
            		//video.play();
            		//video.webkitRequestFullScreen();//chrome的全屏事件
            		//video.webkitEnterFullscreen();//safari的全屏事件
            		//video.webkitDisplayingFullscreen();//safari的全屏事件
            		//fuck!apple!
            		$(video).get(0).play();   //不用get直接$(video).play()也可以播放的     
      			$(video).get(0).webkitEnterFullscreen();//必须通过get(0)才能实现全屏  
            	}else if(mozFull){
            		$(video).show();
            		video.play();
            		video.mozfullscreenchange();
            	}else{
            		console.error("unsupport fullscreen!");
            	}

            	// $("#"+opt.id).show();
//             	
            	// _V_(opt.id).play();
				// _V_(opt.id).requestFullScreen();

            });


还有还有一个要点。就是如果video元素是动态生成的,一开始的隐藏是必须用css实现的而不能用jquery的hide()函数。否则也是不会全屏的。

(function($){
    //成员变量
    var videos = [];//全局audio数组,用来保存所有的audio对象。控制当前只有一个audio在播放并将暂停其它audio并切换icon
    var defaults = {
		pageIndex: 0,
        liIndex: 0,
        left: 0,
        top: 0,
        width:"auto",
        height:"auto",
        index:0,
		playInContext:false,//是否通过上下文播放
		mp4:"",//mp4视频地址
		webm:"",//web视频地址
		autoplay:true,//默认播放
		loop:false,//循环
		poster:"",//封面
		contextId:"videoContextID",
		effectType:"video",
	}
	
    function Video(obj){
    	this.options = {};
		//获取参数
		if (obj) {
			this.options = $.extend({}, defaults, obj);
			init(this);
		} else {
			console.error("no params");
		}
		
        
    }
    
    function init(target) {
		if($("#"+target.options.id).length != 0){
			console.error(target.options.id + " already exist!");
			return;
		}
		if(createHtml(target)){
			createEffect(target.options);
		}
	}
	
	//获取所在的页面位置
	function getWrapper(target) {
		target.wrapper = $("ul.pageUl:eq(" + target.options.pageIndex + ")").find("li.pageLi").eq(target.options.liIndex);
		if(target.wrapper.length != 1){
			console.error("error to find video wrapper!");
		}
	}
	
	//创建特效DOM元素
	function createHtml(target) {
		var that = target, innerHtml = "",opt = target.options;
		getWrapper(that);
		var element = document.createElement("video");
		element.setAttribute("id",opt.id);
		element.setAttribute("class","video");
		if(opt.liIndex > 0){
			opt.top = globals.screenHeight * opt.liIndex + opt.top;
		}
		element.setAttribute("style","position:absolute;z-index:" + opt.index + ";left:" + opt.left + "px;top:" + opt.top + 'px;');
		element.setAttribute("autobuffer","true");
		element.setAttribute("preload","auto");
		element.setAttribute("controls","controls");
		element.setAttribute("width",opt.width);
		element.setAttribute("height",opt.height);
		if(opt.loop)
			element.setAttribute("loop",opt.loop);
		if(opt.poster)
			element.setAttribute("poster",opt.poster);
		if(opt.autoplay)
			element.setAttribute("autoplay",opt.autoplay);
		
		if(opt.mp4){
			var source = document.createElement("source");
			source.setAttribute("src",opt.mp4);
			source.setAttribute("type","video/mp4");
			element.appendChild(source);
		}
		if(opt.webm){
			var source = document.createElement("source");
			source.setAttribute("src",opt.webm);
			source.setAttribute("type","video/webm");
			element.appendChild(source);
		}
		if(opt.ogv){
			var source = document.createElement("source");
			source.setAttribute("src",opt.ogv);
			source.setAttribute("type","video/ogv");
			element.appendChild(source);
		}
		
		// var html = "<video width='" + opt.width + "' height='" + opt.height + "' controls id='" + opt.id + 
			// "' poster='" + opt.poster + "' >";
		// if(opt.mp4){
			// html += "<source src='" + opt.mp4 + "' type='video/mp4' />";
		// }
		// html += "</video>";
		
		if(that.wrapper){
			that.wrapper.append(element);
			if(opt.playInContext && opt.contextImg){
				$("#"+ opt.id).css({'visibility' : 'hidden', 'display' : 'none'});
				//上下文控制的DIV
				var contextHtml = "<div id='" + opt.id + "_context' style='z-index:" + parseInt(opt.index) + ";position:absolute;width:" + opt.width + 
					"px;height:" + opt.height + "px;left:" + opt.left + "px;top:" + 0 + "px;' ><img src='" + opt.contextImg + "'></div>";
				that.wrapper.append(contextHtml);
			}
			return true;
		}else{
			console.error("error to create video html element");
			return false;
		}
	}
    
    //类成员方法
    Video.prototype.pauseVideo = function(){
        this.video.pause();
    };
     
    //创建特效
	function createEffect(options){
        var video = $("#" + options.id)[0];//获取video元素;

        video.addEventListener("error", function(){
            //The code property of the MediaError Object returns a number representing the error state of the audio/video:
            //1 = MEDIA_ERR_ABORTED - fetching process aborted by user
            //2 = MEDIA_ERR_NETWORK - error occurred when downloading
            //3 = MEDIA_ERR_DECODE - error occurred when decoding
            //4 = MEDIA_ERR_SRC_NOT_SUPPORTED - audio/video not supported
            switch (video.error.code) {
                case MediaError.MEDIA_ERROR_ABORTED:
                    console.log("视频的下载过程被中止。");
                    break;
                case MediaError.MEDIA_ERROR_NETWORK:
                    console.log("网络发生故障,视频的下载过程被中止。");
                    break;
                case MediaError.MEDIA_ERROR_DECODE:
                    console.log("解码失败。");
                    break;
                case MediaError.MEDIA_ERROR_SRC_NOT_SUPPORTED:
                    console.log("不支持播放的视频格式。");
                    break;
                default:
                    console.log("视频格式错误。" + video.error.code);
					$("#"+options.playBtn).remove();
					$("#"+options.pauseBtn).remove();
					break;
            }
            //$(video).remove();
        }, false);
        if (options.playInContext == true) { //默认播放
            var opt = options;
            $("#" + opt.id + "_context").bind("click",function(){
            	var enableFullScreen = video.webkitSupportsFullscreen;
            	var mozFull = video.mozfullscreenchange;
            	if (enableFullScreen) {
            		$(video).show();
            		//video.load();
            		//video.play();
            		//video.webkitRequestFullScreen();
            		//video.webkitEnterFullscreen();
            		//video.webkitDisplayingFullscreen();
            		//fuck!apple!
            		$(video).get(0).play();        
      				$(video).get(0).webkitEnterFullscreen();  
            	}else if(mozFull){
            		$(video).show();
            		video.play();
            		video.mozfullscreenchange();
            	}else{
            		console.error("unsupport fullscreen!");
            	}
            });
        }
	}
    
    //释放特效
    Video.prototype.destroy = function()
	{
		$("#" + this.options.id).unbind().remove();
	}
	
	window.Video = Video;
})(jQuery);



参考资料
apple的VIDEO api 说明
http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/HTMLVideoElementClassReference/HTMLVideoElement/HTMLVideoElement.html

解决办法:
http://stackoverflow.com/questions/9486924/webkitenterfullscreen-using-external-button-works-in-chrome-and-safari-but-not
分享到:
评论

相关推荐

    为了解决在safari浏览器video标签无法播放视频的问题

    总结来说,解决Safari浏览器`&lt;video&gt;`标签无法播放视频的问题主要涉及理解浏览器对视频格式的支持情况,提供多格式视频源,使用JavaScript库增强兼容性,以及检查用户的浏览器设置。对于开发者来说,熟悉这些技术和...

    Video In to AXI4-Stream v4.0 汉化手册

    Video In to AXI4-Stream v4.0 汉化手册知识点总结 本篇文章将对 Video In to AXI4-Stream v4.0 汉化手册进行详细的知识点总结,涵盖了 LogiCORE IP 产品指南的主要内容,包括概观、功能摘要、应用、许可和订购信息...

    iConv -convert video files to iPad, iPhone or iPod.rar

    【标题】"iConv -convert video files to iPad, iPhone or iPod.rar" 提供的是一个针对iOS设备的视频转换应用源代码。这个应用主要是为了帮助用户将各种格式的视频转换为适用于iPad、iPhone或iPod播放的格式。在iOS...

    【应用】★★★★★-iConv -convert video files to iPad, iPhone or iPod.zip

    【应用】★★★★★-iConv -convert video files to iPad, iPhone or iPod.zip【应用】★★★★★-iConv -convert video files to iPad, iPhone or iPod.zip 1.适合学生学习研究参考 2.适合个人学习研究参考 3.适合...

    video的原生制作

    - `videoElement.play()` 和 `videoElement.pause()`:开始和暂停播放。 - `videoElement.currentTime`:获取或设置视频当前播放时间。 - `videoElement.volume`:设置或获取音量。 - `videoElement.muted`:...

    IOS源码之【应用】iConv -convert video files to iPad, iPhone or iPod.rar

    【标题】"IOS源码之【应用】iConv -convert video files to iPad, iPhone or iPod.rar" 提供的是一款iOS应用程序的源代码,名为iConv,它的主要功能是转换视频文件,使其能在iPad、iPhone或iPod上播放。这个源码库...

    Image and Video Processing in the Compressed Domain.pdf

    Image and Video Processing in the Compressed Domain presents the fundamentals, properties, and applications of a variety of image transforms used in image and video compression. It illustrates the ...

    VideoJS —— HTML5 视频播放器

    &lt;video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264" poster="***" data-setup='{}'&gt; ***" type='video/mp4'&gt; &lt;/video&gt; ``` 关于上面的代码片段...

    video.js插件

    - **跨浏览器兼容性**:除了 IE8,video.js 也兼容其他主流浏览器,如 Chrome、Firefox、Safari 和 Edge。 - **响应式设计**:video.js 可以适应不同设备和屏幕尺寸,提供良好的移动体验。 - **自定义主题**:通过 ...

    禁止iPhone Safari video标签视频自动全屏的办法

    苹果出于用户体验考虑,限制了在Safari中非全屏播放视频的能力,因此,对于纯Web环境,我们可以说没有直接的方法可以禁止iPhone Safari中的`&lt;video&gt;`标签视频自动全屏。 总结起来,尽管开发者社区提出了许多尝试和...

    Safari HTML5 Audio and Video Guide

    文档还提到了Appled公司的商标和版权,包括了iPhone、iPod、iPod touch、Mac、MacOS、QuickTime和Safari等。这些品牌和产品的所有权属于苹果公司,并且在世界范围内注册了商标。这一点对品牌保护有着重要的意义,...

    video.js-5.x_VideoJS_源码

    1. **跨浏览器兼容性**:VideoJS 5.x支持所有主流浏览器,包括Chrome、Firefox、Safari、Edge和IE9+,确保用户能在各种环境下顺畅观看视频。 2. **自定义化**:VideoJS允许开发者通过CSS和JavaScript轻松定制播放器...

    video.js+video.ads.js js视频与广告插件

    1. **跨浏览器兼容性**:`video.js`支持所有主流浏览器,包括Chrome、Firefox、Safari、Edge和Internet Explorer,确保在各种环境下都能提供一致的用户体验。 2. **HTML5优先**:它优先使用HTML5的`&lt;video&gt;`标签,...

    HTML5 video播放器全屏(fullScreen)方法实例.docx

    } else if (videoElement.mozRequestFullScreen) { // Firefox videoElement.mozRequestFullScreen(); } else if (videoElement.msRequestFullscreen) { // IE11 videoElement.msRequestFullscreen(); } else ...

    H5 Video标签调用摄像头进行录像,兼容苹果、安卓系统、可在微信浏览器正常使用

    在这个场景中,我们利用`&lt;video&gt;`标签的特定属性来实现调用用户设备的摄像头进行录像,并且确保这个功能在苹果iOS系统(如iPhone和iPad)和安卓Android系统上的浏览器,以及微信内置的浏览器中都能正常工作。...

    Tencent- CNN in MRF: Video Object Segmentation Spatio-Temporal MRF

    This paper addresses the problem of video object segmentation, where the initial object mask is given in the first frame of an input video. We propose a novel spatiotemporal Markov Random Field (MRF) ...

    demo.vue(基于element框架,添加videojs-markers打点标记插件的demo)

    基于element框架,添加videojs-markers打点标记插件的demo

    VideoControl.zip_GUI VIDEO_In the Frame_frame grabber_snap_video

    VideoControl - launch a GUI to control image acquisition session: The GUI will help you in: craeting the video object, previewing and snap shotting, controlling frame grabber parameters, saving data ...

    ae插件element

    Element 3D 是由Video Copilot开发的一款强大三维模型渲染和动画工具,它允许用户在After Effects这个2D环境中直接创建和编辑3D元素,无需跳出软件进行复杂的3D建模。 在After Effects中使用Element 3D,可以实现...

Global site tag (gtag.js) - Google Analytics