Opera 和 MP3 Flash 后备使用 MediaElement.js 的 FireFox

发布于 2024-11-14 11:56:18 字数 2077 浏览 2 评论 0原文

我正在尝试将 mediaelement.js 添加到我的网站,以便为特定页面上的任何 MP3 链接提供单个播放器。该设计在 IE 9 和 Chrome 11(支持 HTML5 MP3)上运行良好,但在 Opera 11 和 FireFox 4 上存在 Flash 回退问题。单击页面上的任何 MP3 链接都会使用 .setSrc( ) 媒体元素播放器的方法来更改播放器的来源,但在 Opera 和 FF 中,第一次调用此方法时,会返回错误“this.media.setSrc is not a功能”。此后对该函数的任何调用都可以正常工作。

另一个问题是包含播放器的元素被隐藏“display:none”然后再次显示后,调用 .pause() 函数会产生错误“this.pluginApi.pauseMedia is not a功能”。抛出该错误后,后续调用可以正常工作,直到该元素被隐藏并再次显示。

这是相关代码,非常感谢任何帮助。

<script type="text/javascript" src="../js/mejs/mediaelement-and-player.min.js"></script>
<script type="text/javascript" src="../js/media.js"></script>
<div id="mediaPlayerFooter" class="mediaPlayerWrapper">
    <div id="mediaPlayer">
        <audio id="mp3Player" src="mp3/null.mp3" autoplay="autoplay" type="audio/mp3"></audio>  
    </div>
    <div id="closeButtonWrapper"><p><a id="closeButton" href="#close">Close</a></p></div>
</div>

$(function() {
    // Show the footer, load the MP3 file, and play.
    $("a[href*='.mp3']").click(function(e) {
        e.preventDefault();
        PlayMP3($(this).prop('href'));
    }); 

    // Stop the MP3 playback and close the footer.
    $('#closeButton').click(function(e) {
        e.preventDefault();
        ClosePlayer();
    });
});
function CreatePlayer() {
    var player = new MediaElementPlayer('#mp3Player',{
        audioWidth: 250, 
        startVolume: 1.0
    });
    return player;
}
function PlayMP3(sourceUrl){
    $('#mediaPlayerFooter').slideDown(750);
    var player = CreatePlayer();
    try {
        player.pause();
        player.setSrc(sourceUrl);
        player.load();
        player.play();
    }
    catch(err)
    {
        txt="There was an error loading the MP3.  ";
        txt+="Error message: " + err.message;
        console.log(txt);
    }
}
function ClosePlayer(){
    var player = CreatePlayer();
    player.pause();
    $('#mediaPlayerFooter').slideUp(750);
}

I'm trying to add mediaelement.js to my site to present a single player for any MP3 link on a particular page. The design is working fine for IE 9 and Chrome 11 (which have HTML5 MP3 support), but it has an issue with the flash fallback on Opera 11 and FireFox 4. Clicking any MP3 link on the page uses the .setSrc() method of media element player to change the source of the player, but in Opera and FF, the first time this method is called, it returns error "this.media.setSrc is not a function". Any call to the function after that works fine.

Another issue is after the element containing the player is hidden "display:none" and then displayed again, calling the .pause() function will produce error "this.pluginApi.pauseMedia is not a function". After that error is thrown, subsequent calls work fine until the element is hidden and displayed again.

Here's the relevant code, and any help would be very much appreciated.

<script type="text/javascript" src="../js/mejs/mediaelement-and-player.min.js"></script>
<script type="text/javascript" src="../js/media.js"></script>
<div id="mediaPlayerFooter" class="mediaPlayerWrapper">
    <div id="mediaPlayer">
        <audio id="mp3Player" src="mp3/null.mp3" autoplay="autoplay" type="audio/mp3"></audio>  
    </div>
    <div id="closeButtonWrapper"><p><a id="closeButton" href="#close">Close</a></p></div>
</div>

$(function() {
    // Show the footer, load the MP3 file, and play.
    $("a[href*='.mp3']").click(function(e) {
        e.preventDefault();
        PlayMP3($(this).prop('href'));
    }); 

    // Stop the MP3 playback and close the footer.
    $('#closeButton').click(function(e) {
        e.preventDefault();
        ClosePlayer();
    });
});
function CreatePlayer() {
    var player = new MediaElementPlayer('#mp3Player',{
        audioWidth: 250, 
        startVolume: 1.0
    });
    return player;
}
function PlayMP3(sourceUrl){
    $('#mediaPlayerFooter').slideDown(750);
    var player = CreatePlayer();
    try {
        player.pause();
        player.setSrc(sourceUrl);
        player.load();
        player.play();
    }
    catch(err)
    {
        txt="There was an error loading the MP3.  ";
        txt+="Error message: " + err.message;
        console.log(txt);
    }
}
function ClosePlayer(){
    var player = CreatePlayer();
    player.pause();
    $('#mediaPlayerFooter').slideUp(750);
}

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

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

发布评论

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

评论(1

断舍离 2024-11-21 11:56:18

您还需要添加“flashmediaelement.swf”。

You would need to add "flashmediaelement.swf" as well.

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