0

Okay so I have an html5 audio player that i built with jquery however i need to get the track url from the variable in the url with a get request so that it can then be used in the jquery script. Not sure how to do it. I have the jquery in a seperate file to the markup for easy embedding for users. The url will look like www.mysite.co.uk/player/player.html?url=testing123.mp3.

I can easily get the variable for use in the markup to show the name of the artist etc with PHP but not sure how to do it for the jquery script. I have had a look around but no luck.

Heres the relevent jquery

song = new Audio('THIS IS WHERE THE GET VARIABLE NEEDS TO BE');

I shouldnt think anymore code is needed but if it is just ask.

head

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<?php $url = $_GET['url']; ?> 

<script> // Before jQuery
    var song = new Audio(`<?php echo($url); ?>`);
</script>`
<script type="text/javascript" src="http://newbornsounds.co.uk/player/src/js/js.js"></script>
<script type="text/javascript" src="http://newbornsounds.co.uk/player/src/js/html5slider.js"></script>
2
  • Heres the relevent jquery YMMD. :) Commented Jul 3, 2012 at 1:34
  • @TomaszKowalczyk YMMD = You made my day? Commented Jul 3, 2012 at 1:35

1 Answer 1

4
<?php
$url = $_GET['url']; // Avoid this way! Need to be as safe as possible.
?>

[...]

<head>
    [...]

    <script> // Before jQuery
        var song = new Audio(`<?php echo($url); ?>`);
    </script>`

    [...]
</head>

And remove song from your .js

Sign up to request clarification or add additional context in comments.

10 Comments

@JacobWindsor If url is testing123.mp3 you need to have this file inside the rrot of your website (http://mydomain.com/testing123.mp3)
I do here is one of the tracks on the current site, it will jst play through the usual html player newbornsounds.co.uk/uploads/…
When i reference that same track with the new player nothing happens. I have tried going down all the directories as well with ../ but that just makes the page refresh on play
@JacobWindsor so, your url need to be uploads/19c9aa51c821952c81be46ca9b2e9056.mp3 or, 19c9aa51c821952c81be46ca9b2e9056.mp3 with uploads already included on Audio: song = new Audio('/uploads/<?php echo($url); ?>');
Yes, i forgot to say in the database it already contains ../uploads
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.