Media Element Js 视频播放器无法正常播放

发布于 2025-01-04 21:37:19 字数 1486 浏览 1 评论 0原文

早上好,

我尝试使用 mediaelementjs 视频播放器。 我的 html:

<video id="player" width="758px" height="400px"  controls="controls" autoplay preload="auto">
     <source type="video/flv" src="media/demo.flv" />
</video>

Javascript:

var player = new MediaElementPlayer("#player",{
     success: function (mediaElement, domObject) {

                        // call the play method
                        mediaElement.play();

                    }
             });

我收到此错误:

Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'pauseMedia'
mejs.PluginMediaElement.pausemediaelement-and-player.min.js:28
mejs.MediaElementPlayer.pausemediaelement-and-player.min.js:94
mejs.MediaElementPlayer.meReadymediaelement-and-player.min.js:85
mejs.PluginMediaElement.dispatchEventmediaelement-and-player.min.js:32
mejs.MediaPluginBridge.fireEventmediaelement-and-player.min.js:34
(anonymous function)

出了什么问题?

你能帮我吗?

似乎是这样的:

pause: function () {
    if (this.pluginApi != null) {
        if (this.pluginType == 'youtube') {
            this.pluginApi.pauseVideo();
        } else {
            this.pluginApi.pauseMedia();
        }           


        this.paused = true;
    }
},

更新 我尝试:

var player = new MediaElementPlayer("#player");
player.play(); 

我没有收到错误,但它不播放。

Good morning,

I try work with mediaelementjs video player.
My html:

<video id="player" width="758px" height="400px"  controls="controls" autoplay preload="auto">
     <source type="video/flv" src="media/demo.flv" />
</video>

Javascript:

var player = new MediaElementPlayer("#player",{
     success: function (mediaElement, domObject) {

                        // call the play method
                        mediaElement.play();

                    }
             });

I obtain this error:

Uncaught TypeError: Object #<HTMLEmbedElement> has no method 'pauseMedia'
mejs.PluginMediaElement.pausemediaelement-and-player.min.js:28
mejs.MediaElementPlayer.pausemediaelement-and-player.min.js:94
mejs.MediaElementPlayer.meReadymediaelement-and-player.min.js:85
mejs.PluginMediaElement.dispatchEventmediaelement-and-player.min.js:32
mejs.MediaPluginBridge.fireEventmediaelement-and-player.min.js:34
(anonymous function)

What's wrong?

Can you help me please?

Seems it call this:

pause: function () {
    if (this.pluginApi != null) {
        if (this.pluginType == 'youtube') {
            this.pluginApi.pauseVideo();
        } else {
            this.pluginApi.pauseMedia();
        }           


        this.paused = true;
    }
},

Update
I try:

var player = new MediaElementPlayer("#player");
player.play(); 

I dont' obtain error but it doesn't play.

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

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

发布评论

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

评论(3

寄居人 2025-01-11 21:37:19

我正在使用这个:

//Global player
var Player = {};

    var videoDiv = document.getElementById('videoDiv');

    if(url.search("youtube") >= 0){
        videoDiv.innerHTML = '<video width="480" height="270" id="videoPlayer"><source type="video/youtube" src="'+url+'" /></video>';

    }else{
        videoDiv.innerHTML = '<video width="480" height="270" id="videoPlayer" src="'+url+'" />';

    }

    $('video').mediaelementplayer({
        success: function(media, node, playerElement) {

            Player = playerElement.media;

            //console.log('mode: ' + media.pluginType);

            Player.addEventListener("timeupdate", function( event ) {

                if(Player.paused) return;

                Editor.setTime(Math.round(Player.currentTime));

            });
            Player.addEventListener("seeked", function( event ) {

                Editor.setTime(Math.round(Player.currentTime));

            }); 
            Player.addEventListener("progress", function( event ) {

                if(Player.paused) return;

                console.log('currentTime '+Player.currentTime);
                console.log('progress '+Player.buffered.length);
                var count = Player.buffered.length;
                for(i=0;i<count;i++){

                    console.log('start ',Player.buffered.start(i),'end ',Player.buffered.end(i));

                }

            }); 
            Player.addEventListener("load", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("error", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("playing", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("canplay", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("loadeddata", function( event ) {

                console.log(event);

            }); 
        }
    });


// You can access the Player obj outside the function scope, because it is global
// But only after the player has been loaded!

HTML:

<div id="videoDiv" style="width: 360px; height: 300px;" ></div>

I`m using this:

//Global player
var Player = {};

    var videoDiv = document.getElementById('videoDiv');

    if(url.search("youtube") >= 0){
        videoDiv.innerHTML = '<video width="480" height="270" id="videoPlayer"><source type="video/youtube" src="'+url+'" /></video>';

    }else{
        videoDiv.innerHTML = '<video width="480" height="270" id="videoPlayer" src="'+url+'" />';

    }

    $('video').mediaelementplayer({
        success: function(media, node, playerElement) {

            Player = playerElement.media;

            //console.log('mode: ' + media.pluginType);

            Player.addEventListener("timeupdate", function( event ) {

                if(Player.paused) return;

                Editor.setTime(Math.round(Player.currentTime));

            });
            Player.addEventListener("seeked", function( event ) {

                Editor.setTime(Math.round(Player.currentTime));

            }); 
            Player.addEventListener("progress", function( event ) {

                if(Player.paused) return;

                console.log('currentTime '+Player.currentTime);
                console.log('progress '+Player.buffered.length);
                var count = Player.buffered.length;
                for(i=0;i<count;i++){

                    console.log('start ',Player.buffered.start(i),'end ',Player.buffered.end(i));

                }

            }); 
            Player.addEventListener("load", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("error", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("playing", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("canplay", function( event ) {

                console.log(event);

            }); 
            Player.addEventListener("loadeddata", function( event ) {

                console.log(event);

            }); 
        }
    });


// You can access the Player obj outside the function scope, because it is global
// But only after the player has been loaded!

HTML:

<div id="videoDiv" style="width: 360px; height: 300px;" ></div>
萌化 2025-01-11 21:37:19

至于我从远处可以看出,我认为 MediaElementPlayer 需要一个 mediaElement.pause();

我从 mediaElementjs.com 找到了这个:

<前><代码><脚本>;
// JavaScript 对象供以后使用
var player = new MediaElementPlayer('#player',/* 选项 */);
// ...更多代码...
玩家.暂停();
player.setSrc('mynewfile.mp4');
播放器.play();

也许尝试设置暂停();并看看它给出了什么错误。

As for what I can tell from a far I think that the MediaElementPlayer needs a mediaElement.pause();

I've found this from mediaElementjs.com:

<script>
// JavaScript object for later use
var player = new MediaElementPlayer('#player',/* Options */);
// ... more code ...
player.pause();
player.setSrc('mynewfile.mp4');
player.play();
</script>

Maybe try to set the pause(); and see what errors it gives.

雨后咖啡店 2025-01-11 21:37:19

试试这个:

var player = new MediaElementPlayer("#player");
player.play();

或者这个:

new MediaElement('player', {
  success: function (mediaElement, domObject) {

  },false);
 mediaElement.play();
});

try this:

var player = new MediaElementPlayer("#player");
player.play();

or this:

new MediaElement('player', {
  success: function (mediaElement, domObject) {

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