在jPlayer中使用PHP从JSON动态填充播放列表 [英] Dynamically populate playlist with JSON from PHP in jPlayer

查看:171
本文介绍了在jPlayer中使用PHP从JSON动态填充播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP,可以在目录中创建mp3文件的JSON数组. PHP的JSON数组输出为:

I have a PHP that create a JSON array of mp3 files in a directory. The JSON array output from PHP is :

[{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with  the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}]

好,这似乎是JQuery.jPlayer所期望的.

Fine, it seems to be what is expected by JQuery.jPlayer.

现在在基本的jplayer.js文件中:

Now in a basic jplayer.js file I have :

$(document).ready(function(){

new jPlayerPlaylist({
    jPlayer: "#jquery_jplayer_1",
    cssSelectorAncestor: "#jp_container_1"
}, [
    //I guess my JSON array should come here
    // but no idea on how I put it in...
], {
    swfPath: "../js",
    supplied: "mp3",
    wmode: "window"
});
});

我的问题是我无法将JSON数组放在应有的位置(请参阅js代码中的注释)

My problem is I can't put my JSON array in the place it should be (see comments in js code)

任何帮助将不胜感激! 原谅我的英语不是我的母语 预先感谢

Any help would be very appreciate ! Forgive my english it's not my native tongue Thanks in advance

大家好, 对于那些有兴趣的人,我找到了一个解决方案: 我的JS文件是:

Hi all, For those who are interested I find a solution : My JS file is :

$(document).ready(function(){
    var cssSelector = {
        jPlayer: "#jquery_jplayer_1", 
        cssSelectorAncestor: "#jp_container_1"
    };
    var playlist = []; // Empty playlist
    var options = {
        swfPath: "./js", 
        supplied: "mp3"
    };
    var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
    $.getJSON("../PHP/radio.php",function(data){  // get the JSON array produced by my PHP
        $.each(data,function(index,value){
            myPlaylist.add(value); // add each element in data in myPlaylist
        })
    }); 
});

推荐答案

为什么不只使用javascript:

Why dont you just put in javascript:

var playlist = [{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with  the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}];

$(document).ready(function(){

  new jPlayerPlaylist({
    jPlayer: "#jquery_jplayer_1",
    cssSelectorAncestor: "#jp_container_1"
  },
  playlist,
  {
    swfPath: "../js",
    supplied: "mp3",
    wmode: "window"
  });
});

您甚至可以使用PHP生成您的playlist变量.

You can even use PHP to generate your playlist var.

这篇关于在jPlayer中使用PHP从JSON动态填充播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆