Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to know about SounManager Player ID

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 ??

like image 373
Mohammad Umer Avatar asked Oct 17 '22 19:10

Mohammad Umer


1 Answers

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.

like image 104
Evhz Avatar answered Oct 20 '22 22:10

Evhz