让jPlayer再次播放而不重新加载页面

时间:2011-12-10 20:16:35

标签: ajax jplayer

如果有调度员的警告信息,我们的用户IE7和我需要播放声音。

这在页面加载时工作正常,但是如果调度程序打开页面并且之前已收到消息并响应....那么当收到新消息时,声音似乎不起作用。

使用jPlayer我做错了什么?只要信息存在,我只想继续播放声音。

我的Ajax电话

$.ajax({
    type: "POST",
    url: "/Messages/ViewMessages.aspx/GetMessages",
    data: "{messageId:" + 45 + "}",
    contentType: "application/json; charset=utf-8",
    cache: false,
    dataType: "json",
    timeout: 60000,
    success: function(data) {
        if (data.d.length > 0) {
            showPanic(data.d);
            var sound = "/JavaScript/jQuery/UI/js/Audio/Air Plane Ding-SoundBible.com496729130.mp3";
     playSound(sound);
        }
        else {
            $("#dialog").dialog("destroy");
        }

    }

function playSound(sound) {
            $("#jquery_jplayer_1").jPlayer({
                ready: function() {
                    $(this).jPlayer("setMedia", {
                        mp3: sound
                    }).jPlayer("play");
                },
                loop: true,
                swfPath: "/JavaScript/jQuery/UI/js/jQuery.jPlayer.2.1.0/Jplayer.swf",
                supplied: "mp3"
            });
            $("#jquery_jplayer_1").jPlayer("play");}

2 个答案:

答案 0 :(得分:3)

playSound中尝试此更改。 Click here to run the code in jsFiddle

function playSound(sound) {
    var $player = $("#jquery_jplayer_1");
    if ($player.data().jPlayer && $player.data().jPlayer.internal.ready === true) {
        $player.jPlayer("setMedia", {
            mp3: sound
        }).jPlayer("play");
    }
    else {
        $player.jPlayer({
            ready: function() {
                $(this).jPlayer("setMedia", {
                    mp3: sound
                }).jPlayer("play");
            },
            loop: true,
            swfPath: "/JavaScript/jQuery/UI/js/jQuery.jPlayer.2.1.0/Jplayer.swf",
            supplied: "mp3"
        });
    }
}

答案 1 :(得分:0)

我的jPlayer div在一个实现Display:none的类中。这样就无法访问jPlayer的播放,暂停,停止功能。

相关问题