Html5 在 Safari 中更改视频失败

发布于 2025-01-05 16:26:09 字数 1478 浏览 1 评论 0原文

我包含了一个带有 html5 的视频,并且我有一个可以更改视频的菜单。

该菜单在 Firefox、Opera 和 Chrome 中运行良好,但在 Safari 中运行不佳。

我有这个html代码:

<div id="tele">
    <video id="v" width="254" height="204">
     <source id="ogg" src="/media/joies.ogv" type="video/ogg" /> 
     <source id="mp4" src="/media/joies.mp4" type="video/mp4" />
     <source id="webm" src="/media/joies.webm" type="video/webm" /> 
     <object id="flash" type="application/x-shockwave-flash"
        data="player.swf?file=joies.mp4">
        <param id="flash2" name="movie" value="player.swf?file=joies.mp4" />
    </object> </video>


</div>

<li><a href="#" class="activo"
onClick="changeVideo('/media/joies.ogv','/media/joies.mp4','/media/joies.webm','player.swf?file=joies.mp4','player.swf?file=joies.mp4')">1</a>

这个Javascript:

function changeVideo(v,x,w,y,z) {

    document.getElementById("ogg").src=v;
    document.getElementById("mp4").src=x;
    document.getElementById("flash").data=y;
    document.getElementById("flash2").value=z;
    document.getElementById("webm").src=w;
    var video = document.getElementById('v');
    video.load();
    video.play();
    }

访问网页: http://81.35.152.41:8888 /index.php/ca/static/zapping#

为什么 Safari 中无法运行更改视频的菜单?

谢谢

问候

I included a videos with html5, and I have a menu that change the video.

The menu runs well in Firefox, Opera and Chrome but not in Safari.

I have this html code:

<div id="tele">
    <video id="v" width="254" height="204">
     <source id="ogg" src="/media/joies.ogv" type="video/ogg" /> 
     <source id="mp4" src="/media/joies.mp4" type="video/mp4" />
     <source id="webm" src="/media/joies.webm" type="video/webm" /> 
     <object id="flash" type="application/x-shockwave-flash"
        data="player.swf?file=joies.mp4">
        <param id="flash2" name="movie" value="player.swf?file=joies.mp4" />
    </object> </video>


</div>

<li><a href="#" class="activo"
onClick="changeVideo('/media/joies.ogv','/media/joies.mp4','/media/joies.webm','player.swf?file=joies.mp4','player.swf?file=joies.mp4')">1</a>

And this Javascript:

function changeVideo(v,x,w,y,z) {

    document.getElementById("ogg").src=v;
    document.getElementById("mp4").src=x;
    document.getElementById("flash").data=y;
    document.getElementById("flash2").value=z;
    document.getElementById("webm").src=w;
    var video = document.getElementById('v');
    video.load();
    video.play();
    }

To visit the web: http://81.35.152.41:8888/index.php/ca/static/zapping#

Why the menu to change video not runs in Safari?

Thanks

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不奢求什么 2025-01-12 16:26:09

将 mp4 节点放在其他节点之上,然后它可能会起作用。
如果这不起作用,请完全删除源节点并使用视频节点的 src 属性。然后添加对兼容编解码器的检查到changeVideo() --> IE9 中的video.canPlayType("video/mp4") (对于每种类型,最好在循环中)

为我解决了问题。后来测试了Safari,不知道是否有同样的问题。

我使用这个函数进行源测试:

    var VIDEO = document.getElementById("myVideo");
        function listSource(source,sources) {
            var type,
                ext = source.split('.').pop();
            switch(ext) {
                case "mp4":
                case "m4v": 
                    ext = "mp4";
                    type = "video/mp4";
                break;
                case "webm":
                    type = "video/webm";
                break;
                case "ogv":
                    type = "video/ogg";
                break;
                default:
                    console.log('invalid file extension: '+source);
                    return sources;
            }
            if( !VIDEO.canPlayType(type) ) {
                return sources; // only add video to list if the current browser can actually play it
            }
            sources.push({ src: source, type: type });
            return sources;
        }


    var sources_ok = [];
    var sources = ["http://domain.com/test.mp4", "http://domain.com/test.webm", "http://domain.com/test.ogv"]; // example

    for(var i=0,maxi=sources.length;i<maxi;i++) {
        sources_ok = listSource(sources[i],sources_ok);
    }

put the mp4-node on top of the others, then it might work.
if that does not work, remove the source-nodes completely and use the src attribute of the video-node. Then add a check for compatible codecs to changeVideo() --> video.canPlayType("video/mp4") (for each type, best in a loop)

in IE9 that fixed problems for me. tested Safari later so dunno if it has the same problem.

I use this function for source-testing:

    var VIDEO = document.getElementById("myVideo");
        function listSource(source,sources) {
            var type,
                ext = source.split('.').pop();
            switch(ext) {
                case "mp4":
                case "m4v": 
                    ext = "mp4";
                    type = "video/mp4";
                break;
                case "webm":
                    type = "video/webm";
                break;
                case "ogv":
                    type = "video/ogg";
                break;
                default:
                    console.log('invalid file extension: '+source);
                    return sources;
            }
            if( !VIDEO.canPlayType(type) ) {
                return sources; // only add video to list if the current browser can actually play it
            }
            sources.push({ src: source, type: type });
            return sources;
        }


    var sources_ok = [];
    var sources = ["http://domain.com/test.mp4", "http://domain.com/test.webm", "http://domain.com/test.ogv"]; // example

    for(var i=0,maxi=sources.length;i<maxi;i++) {
        sources_ok = listSource(sources[i],sources_ok);
    }
筱果果 2025-01-12 16:26:09

如果您在加载视频后更改视频源,safari 将不会加载该视频。您必须克隆视频,删除原始视频并将克隆的容器附加到其位置。

If you change a video's source after it has already loaded, safari will not load the video. You must Clone the video, delete the original and append the cloned container in its place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文