I am using bar-ui js of soundmanager.
http://www.schillmania.com/projects/soundmanager2/demo/bar-ui/
I have many players so i don't know about soundid what i want to when page load player should load.
http://support.simplepodcaster.com/auto-timestamps/
See i have three player on my page i want ....
I tried that
var mySoundObject = soundManager.createSound({
id: 'mySound',
url: '/audio/mysoundfile.mp3',
// optional sound parameters here, see Sound Properties for full list
volume: 50,
autoPlay: true,
whileloading: function() {
jQuery(".playercontent").data('sound-id', this.id);
}
});
But the problem i can get sound-id until i play otherwise i did not able to get id.
Is there any way to get id when page load ??
When you use createSound()
it can generate an id, or be assigned one (as you do now).
In the example you paste, you provide an id, so you are overriding the creation of it from soundmanager. That is your sound will have the id='mySound'
. Following the docs you can see what I write here.
Instead, if you create the sound (or player in your case) you could set an id for each sound, by, for example, creating a hash with the name or url of the mp3 track of that player (so, you can find your sound later by an id you can generate)
Something like this:
var url='/audio/mysoundfile.mp3';
var id=md5(url); // hash it here
var mySoundObject = soundManager.createSound({
id: id,
url: url,
// optional sound parameters here, see Sound Properties for full list
volume: 50,
autoPlay: true
//whileloading: function() {
//jQuery(".playercontent").data('sound-id', this.id);
//}
});
jQuery(".playercontent").data('sound-id', id);
Or simply obtain an id as follows:
var mySoundObject = soundManager.createSound({
url: '/audio/mysoundfile.mp3',
// optional sound parameters here, see Sound Properties for full list
volume: 50,
autoPlay: true,
// whileloading: function() {
// jQuery(".playercontent").data('sound-id', this.id);
// }
});
console.log(mySoundObject.id);
jQuery(".playercontent").data('sound-id', mySoundObject.id);
For both cases, you can use the following method to grab any sound/player you created in your site directly:
var track='/audio/mysoundfile.mp3';
var id= md5(track);
var mySoundObject = soundManager.getSoundById(id);
From other side, there are callbacks you can use like setVolume()
or force the mp3 file to load (any method in the SMSound object has the this.id
field available in context).
But, it is not really necessary to use things like that in order to just get the id of your sound/player.
Maybe with this info you could better organize players on your website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With