Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
ahazdesigns
Posts: 152
Registered: ‎08-25-2010
My Device: 9530, 9550, 9630

Adding delay before playing sound using sound()

ok, so im trying to add a delay before playing a sound in flex. Reason being i want it to show text then play the sound.

 

i cant find anything to go with the sound.play()

 

 

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Adding delay before playing sound using sound()

You can do it a couple of ways:

 

Method 1:

 

/////////////////////////////////////////
private function ButtonPress( event : Event ) : void
{
  var delay :Timer = new Timer( 1000, 1 );
  delay.addEventListener( TimerEvent.TIMER_COMPLETE, PlaySound );
  delay.start();
}

//////////////////////////////////////////////////////////
private function PlaySound( event : Event ) : void
{
 this.sound.play();
}

 

OR

 

setTimeout( PlaySound, 1000 );

.....

private function PlaySound() : void
{
  this.sound.play();
}

 OR

 

setTimeout( PlaySound, 1000, sound );

.....

private function PlaySound( sound : Sound ) : void
{
  sound.play();
}

 

 

Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: Adding delay before playing sound using sound()

Or just add some silence to the beginning of your MP3 using a sound editor. Once compressed it will take up virtually no space.

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Developer
ahazdesigns
Posts: 152
Registered: ‎08-25-2010
My Device: 9530, 9550, 9630

Re: Adding delay before playing sound using sound()

Had tried that but soundbooth removes silent space when saving. What about if I want to make sure a sound stops before playing another?
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: Adding delay before playing sound using sound()

Try:

 

var snd:Sound = new Sound();
var ch:SoundChannel = snd.play();
ch.stop();

Obvious you would not call it this way since it will stop right away, but caching the SoundChannel will allow you to stop it before the next play.