I have a site that has particular alphanumeric ID for every song, say like 57bfab618de4191
In the jQuery player the MP3 song has to be assigned via link.
The jplayer function is this:
$(document).ready(function (){
function playAudio(val) {newVal=val}
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3:".php?file="+newVal });
},
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
});
I want to play different song present in the list for user so I passed a ID of song via button onClick
like this
onClick="playAudio(<?php echo "'".$songid. "'"; ?>)"
Where song ID is the iD of the song specified in database, like 57bfab618de4191
This way I can pass the value, but I am not able to transfer the parameter of playAudio function to the document.ready
function.
I have a site that has particular alphanumeric ID for every song, say like 57bfab618de4191
In the jQuery player the MP3 song has to be assigned via link.
The jplayer function is this:
$(document).ready(function (){
function playAudio(val) {newVal=val}
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3:"http://website./dlb.php?file="+newVal });
},
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
});
I want to play different song present in the list for user so I passed a ID of song via button onClick
like this
onClick="playAudio(<?php echo "'".$songid. "'"; ?>)"
Where song ID is the iD of the song specified in database, like 57bfab618de4191
This way I can pass the value, but I am not able to transfer the parameter of playAudio function to the document.ready
function.
- Echo the ID into a data attribute and get it with jQuery inside the function, and get rid of that inline click handler. – adeneo Commented Sep 9, 2012 at 7:00
- @adeneo how,, actually, can you describe? I don't want page to be refreshed and also , the id is present at the play button of the song and there is list i cant assign the id globally anywhere. I have to use onClick function for specific song – Abhishek Sharma Commented Sep 9, 2012 at 7:04
- I'm guessing something like THIS FIDDLE... – adeneo Commented Sep 9, 2012 at 7:09
-
try
mp3:"http://website./dlb.php?file="+newVal+".mp3"
– Alfred Commented Sep 9, 2012 at 7:09
2 Answers
Reset to default 3var val = 'whateveer'
function playAudio(nval) {
var val = nval;
$("#jquery_jplayer_1").jPlayer({
ready: function(event) {
$(this).jPlayer("setMedia", {
mp3: "http://website./dlb.php?file=" + val
});
},
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
}
no need for $(document).ready
if you need to change songs:
var val = '12345'; // your first song
$(document).ready(function() {
$("#jquery_jplayer_1").jPlayer({
ready: function(event) {
$(this).jPlayer("setMedia", {
mp3: "http://website./dlb.php?file=" + val
});
},
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
});
function playAudio(nval) {
var val = nval;
$("#jquery_jplayer_1").jPlayer({
"setMedia", {
mp3: "http://website./dlb.php?file=" + val
}
});
// --- OR ---
$("#jquery_jplayer_1").changeAndPlay("http://website./dlb.php?file=" + val);
}
More info:
- Changing songs on jPlayer by clicking a link, hosted on Amazon S3
- http://www.jplayer/0.2.1/developer-guide/#jPlayer-change
You need to play with variable scoping.
var newVal = 'default_song_to_play_if_any';
function playAudio(val){
newVal = val;
$("#jquery_jplayer_1").jPlayer("destroy");
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3:"http://website./dlb.php?file="+newVal
});
},
swfPath: "js",
supplied: "mp3",
wmode: "window"
});
}
//use this ready function only if you want to play a default song on load
$(document).ready(function(){
playAudio(newVal);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744771391a4592780.html
评论列表(0条)