Topic: Sound setVolume()

Hi,

I have some problems with sound objects and methods.
I want to loadSound, and then control the volume, for example, I can setVolume(100) after loadSound(url,true) and then setVolume(50) when pressing a button and it's ok, but if I setVolume(0) after loadSound, and then setVolume(100) when pressing the button, there is no change, I can't hear the sound, if I look the value of getVolume, it's set to 100, so the setVolume has made its function, but then, why I can't hear the sound????

Any idea?
Thanks

Re: Sound setVolume()

Is there any extra mute function?
Perhaps there is some kind of mute that is set to true when you use setVolume(0) but it doesn't automatically change back to mute = false when you use setVolume(100)?

Re: Sound setVolume()

I tried with setVolume(10), with no success...if I start playing with setVolume(10) I can't setVolume (100) later... sad

4 (edited by Fabur 2010-02-18 08:27:08)

Re: Sound setVolume()

But the other way round is working? oO

Is this some extra flash function or the internal chumby function?

I can only guess around a bit as I don't know any flash (yet). big_smile


[edit]
I only found this tutorial in the wiki
http://wiki.chumby.com/mediawiki/index. … gle_Button
perhaps it can help a bit (or is completly outdated, as some other code examples)

Re: Sound setVolume()

Chumbera wrote:

Hi,

I have some problems with sound objects and methods.
I want to loadSound, and then control the volume, for example, I can setVolume(100) after loadSound(url,true) and then setVolume(50) when pressing a button and it's ok, but if I setVolume(0) after loadSound, and then setVolume(100) when pressing the button, there is no change, I can't hear the sound, if I look the value of getVolume, it's set to 100, so the setVolume has made its function, but then, why I can't hear the sound????

Any idea?
Thanks

Can you possibly show an example of your code please?

Cheers.

Re: Sound setVolume()

Hi,

Thanks for the link smile I tried to do this:

var global_snd:Sound = new Sound();
var current_volume:Number = global_snd.getVolume();
trace("volumen " + current_volume);
var is_muted:Boolean = false;
function toggleMute () {
if (!is_muted) {
  current_volume = global_snd.getVolume();
  global_snd.setVolume(0);
  is_muted = true;
} else {
  global_snd.setVolume(current_volume);
  is_muted = false;
}
}


global_snd.loadSound("http://10.95.73.156:1111/mp3-32-11-st.mp3",true);
// to start with mute state
toggleMute();

and then for the button:

on (press) {
   
toggleMute();
}


As I mentioned, it works on PC, but not on chumby sad . But, if I delete the toggleMute indication after loadSound, I mean, I start with volume state, I can change to mute state with the button, change to volume again using the button...

7 (edited by cbreeze 2010-02-22 13:20:58)

Re: Sound setVolume()

Hi,

So the issue is in the scope of your variables.  Some of the variables were inaccessible to the function.  If you re-write your code as follows, does it now work?  It did for me.

_root.global_snd = new Sound(_root);
_root.current_volume = _root.global_snd.getVolume();

trace("volumen " + _root.current_volume);

_root.is_muted = false;

function toggleMute () {
    
 if (!_root.is_muted) {
  _root.current_volume = _root.global_snd.getVolume();
  
  _root.global_snd.setVolume(0);
  _root.is_muted = true;
  
 } else {
     
  _root.global_snd.setVolume(_root.current_volume);
  _root.is_muted = false;
  
 }
 
}


_root.global_snd.loadSound(""http://10.95.73.156:1111/mp3-32-11-st.mp3",true);
// to start with mute state
_root.toggleMute();

I assume your putting this code directly on the timeline, though I would suggest making a "class" out of it.

If you have any other questions, let me know.

Cheers.

Re: Sound setVolume()

Thanks,
I've tried your suggestion, but it doesn't work with my Chumby sad

Any idea why??

Re: Sound setVolume()

Could you put some output or something like this in your code.
(Trace doesn't help on the chumby, does it?
Perhaps a textfield will do it?)

So you could check whether your functions get called or not.
A simple text output like "mute is on" and "mute is off" when the function is called.
So when you get no output you know that flash isn't getting to this part of your code.

Re: Sound setVolume()

Chumbera wrote:

Thanks,
I've tried your suggestion, but it doesn't work with my Chumby sad

Any idea why??

I'm baffled.  I'll have to look at it more later.

Cheers.