简体   繁体   中英

jPlayer play next file

I'm trying to use jPlayer for playing background music on service.

Here is my code:

    if (command.indexOf('playmusic') != -1) {
        var player = document.getElementById('jpId');
        $(player).jPlayer(
            {
                ready: function () {
                    $(this).jPlayer("setMedia", {
                        mp3: "../../audio/1.mp3"
                    }).jPlayer("play");
                }, supplied: "mp3"
            }
        );
    }
    if (command.indexOf('playnext') != -1) {
        var player = document.getElementById('jpId');
        $(player).setFile("../../audio/2.mp3");
        $(player).play();
    }

but playnext part of code not working:

Uncaught TypeError: Object [object Object] has no method 'setFile'

What I'm doing wrong?

Thanx!

I think you should do

$('#jpId').jPlayer('setMedia', {
  mp3: '../../audio/2.mp3',
}).jPlayer('play');

Instead of

var player = document.getElementById('jpId');
$(player).setFile("../../audio/2.mp3");
$(player).play();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM