Search code examples
phpaudiojplayer

Embedding PHP in jplayer


I am pulling mp3 file locations from my mysql database using PHP and would like to pass those variables to a script in my page.

I want to know how to have the below file name echo from an array in my database:

var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
{
    m4a:   "downloads/uploads/p170f0vflo1066jbc1l4pp38st01.mp3",
}, {
    cssSelectorAncestor: "#cp_container_1",
    swfPath: "js",
    wmode: "window"
});

So I would need something like this:

var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
{
    m4a: "<?php echo $music_p; ?>",  <---This is what I need (from a database)
}, {
    cssSelectorAncestor: "#cp_container_1",
    swfPath: "js",
    wmode: "window"
});

Solution

  • As @Sean Johnson said it should work if you define $music_p in the same file as the javascript is. For instance in the javascript tags

    <?php $music_p = array("downloads/uploads/p170f0vflo1066jbc1l4pp38st01.mp3") ?>
    
    <script type="text/javascript">
    //JavaScript code (define functions here)
    var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
    {
    m4a: "<?php echo $music_p[0]; ?>",  <----------This is what i want!
    }, {
        cssSelectorAncestor: "#cp_container_1",
        swfPath: "js",
        wmode: "window"
    });
    </script>
    

    I believe this is what you might want to look at.