MEJS 在 setSrc() 之后忽略预加载标签

发布于 2024-12-14 12:50:35 字数 1584 浏览 2 评论 0原文

你好~尝试推出一个基于 MEJS 的视频播放器,并提供用户可切换的视频。

我遇到的问题是,当我调用 setSrc() 时,flash 和 html5 播放器都会在开始播放新视频之前预加载整个视频,无论预加载什么> 标签表示。理想情况下,视频在数据下载时开始播放。

/* code and comments trimmed for your viewing pleasure */
<video src="myvideo1.mp4" width="800" height="450" preload="none" smoothing autoplay></video>

<script>
    var player = new MediaElementPlayer('video', {
        enablePluginDebug: true,
        plugins: ['flash','silverlight'],
        defaultVideoWidth: 800, defaultVideoHeight: 450,
        videoWidth: -1, videoHeight: -1,
        loop: false,
        features: ['playpause','progress','current','duration','fullscreen'], 
        success: function (mediaElement, domObject) { 
            mediaElement.play();
        },
        error: function () { 
            alert('error!');
        }
    });

    var currentVid = 1;

    var vidnames = new Array("(null)",
        "myvideo1.mp4",
        "myvideo2.mp4",
        "myvideo3.mp4");

    function switchvid (vidnum) {
        currentVid = vidnum;

        player.pause();
        player.setSrc( vidnames[vidnum] );
        player.play();

        return false;
    }

</script>

<A HREF="#" onClick="return switchvid(1)"><IMG SRC="ch01x.png"></A>
<A HREF="#" onClick="return switchvid(2)"><IMG SRC="ch02x.png"></A>
<A HREF="#" onClick="return switchvid(3)"><IMG SRC="ch03x.png"></A>

尝试了 preload="none"preloadpreload="auto" 均得到相同的结果...播放器在填充时似乎挂起缓冲区包含整个下载内容,然后开始播放。

howdy ~ tryin' to whip out a MEJS based video player with user switchable vids.

problem i'm havin is when i call setSrc(), both the flash and the html5 player preloads the entire video before it starts playing the new vid, regardless of what the preload tag indicates. ideally the video begins playing as data is downloading.

/* code and comments trimmed for your viewing pleasure */
<video src="myvideo1.mp4" width="800" height="450" preload="none" smoothing autoplay></video>

<script>
    var player = new MediaElementPlayer('video', {
        enablePluginDebug: true,
        plugins: ['flash','silverlight'],
        defaultVideoWidth: 800, defaultVideoHeight: 450,
        videoWidth: -1, videoHeight: -1,
        loop: false,
        features: ['playpause','progress','current','duration','fullscreen'], 
        success: function (mediaElement, domObject) { 
            mediaElement.play();
        },
        error: function () { 
            alert('error!');
        }
    });

    var currentVid = 1;

    var vidnames = new Array("(null)",
        "myvideo1.mp4",
        "myvideo2.mp4",
        "myvideo3.mp4");

    function switchvid (vidnum) {
        currentVid = vidnum;

        player.pause();
        player.setSrc( vidnames[vidnum] );
        player.play();

        return false;
    }

</script>

<A HREF="#" onClick="return switchvid(1)"><IMG SRC="ch01x.png"></A>
<A HREF="#" onClick="return switchvid(2)"><IMG SRC="ch02x.png"></A>
<A HREF="#" onClick="return switchvid(3)"><IMG SRC="ch03x.png"></A>

tried preload="none", preload, preload="auto" all with the same results... player just appears to hang while filling the buffer with the entire download, then begins to play.

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

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

发布评论

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

评论(1

回忆凄美了谁 2024-12-21 12:50:35

显然,load() 函数可以处理这个问题。不清楚 load() 与 PRELOAD 属性(如果有)的关系,但对我来说它现在正在工作。

 var player = new MediaElementPlayer('video', {
    // etc
    success: function (mediaElement, domObject) { 
        mediaElement.load();
        mediaElement.play();
    }
 }

function switchvid (vidnum) {
    currentVid = vidnum;

    player.pause();
    player.setSrc( vidnames[vidnum] );
    player.load();
    player.play();

    return false;
}

apparently, the load() function handles this. not clear on load()'s relationship to the PRELOAD attributes (if any), but for me it is working now.

 var player = new MediaElementPlayer('video', {
    // etc
    success: function (mediaElement, domObject) { 
        mediaElement.load();
        mediaElement.play();
    }
 }

function switchvid (vidnum) {
    currentVid = vidnum;

    player.pause();
    player.setSrc( vidnames[vidnum] );
    player.load();
    player.play();

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