none
Sound.Play ( only once..) RRS feed

  • Question

  • In 0.5 I can play a sound (user file) only once.  It makes no difference if the subsequent files are different files.  In my application, the sound cannot stop the application from running, so Sound.Stop isn't workable.

    There has been a discussion of this being a bug but there also was a reference to it being fixed in 0.4.

    TIA

    Dan

    Sunday, August 23, 2009 8:07 PM

Answers

  • This looks like an issue I think that was raised before - sounds not rewinding after they have finished.

    If you Sound.Stop before each Sound.Play it works.

    TextWindow.WriteLine(path+"r150.wma")
    Sound.Stop(path+"r150.wma")
    Sound.Play(path+"r150.wma")
    Program.Delay(5000)

    etc.
    Monday, August 31, 2009 1:33 PM
    Moderator

All replies

  • what? did you try:

    sound.stop(soundbla.mp3)
    sound.play(soundbla.mp3)

    or what are you trying to achieve??
    Live for nothing, OR CODE FOR SOMETHING! (Happy now vijaye?^^)
    Sunday, August 23, 2009 8:13 PM
  • Dan,

    Can you supply a code segment to show the problem with a short explanation of what you want it to do that it doesn't.

    For example the following behaves as I would expect, where wma is a wma file path.

    Sound.Play(wma)
    TextWindow.WriteLine("Playing")
    Program.Delay(5000)
    Sound.Stop(wma)
    TextWindow.WriteLine("Stopped")
    TextWindow.WriteLine("Started")
    Sound.Play(wma)
    Sunday, August 23, 2009 9:16 PM
    Moderator
  • Dan,

    Can you supply a code segment to show the problem with a short explanation of what you want it to do that it doesn't.

    For example the following behaves as I would expect, where wma is a wma file path.

    Sound.Play(wma)
    TextWindow.WriteLine("Playing")
    Program.Delay(5000)
    Sound.Stop(wma)
    TextWindow.WriteLine("Stopped")
    TextWindow.WriteLine("Started")
    Sound.Play(wma)
    isnt it smarter to use sound.playandwait ??

    Live for nothing, OR CODE FOR SOMETHING! (Happy now vijaye?^^)
    Sunday, August 23, 2009 9:18 PM
  • Below is a snippet.  It is a countdown timer with a warning at a variable seconds.  The warning is a .wma file to turn to a praticular course.  In some cases, the course is the same so the word "continue.wma" is spoken.  As I go through the various loops, the first call to each course "r170.wma" for example plays fine.  However, and later call to that same file name is ignored (that is, no sound is played).

    I don't want to pause because that would interrupt the countdown seconds being shown.  Except for the "2nd time doesn't play" problem, the code works just fine.

    I've watched the first call be played and subsequent ones ignored with the WriteLine.

    Dan


       ElapsedSeconds=ElapsedSeconds+1
        NextBlockSeconds=NextBlockSeconds+1
        SecToGo=LegInSeconds-ElapsedSeconds
        'TextWindow.WriteLine("HeadStart:"+AudioHeadStart+" "+SecToGo + " of " +LegInSeconds + " elapsed " + ElapsedSeconds )
        If SecToGo=AudioHeadStart then
            OnTheFives=(math.floor(NextLegCourse/5))*5
            'TextWindow.WriteLine("CHECK: "+OnTheFives + " of " +TurnTo )
            If TurnTo="C" then
             thissoundpath="c:\auxsar\captain\"+"continue.wma"
            endif
            If TurnTo="R" then
              thissoundpath="c:\auxsar\captain\"+TurnTo+OnTheFives+".wma"
              TextWindow.WriteLine("R "+TurnTo+OnTheFives)
            endif
           
            TextWindow.WriteLine(thissoundpath)
            Sound.Play(thissoundpath)
           
    Sunday, August 30, 2009 5:46 PM
  • Its hard to help much from here, I don't know what your variable values are, whether it is called by subroutine, events etc.

    If you are doing clock and timer countdowns, you can use the SmallBasic Clock command to keep track of the time rather than 'ElapsedSeconds=ElapsedSeconds+1'.  I may be missing something here, but then if you use the Clock functionality, possibly with timer events, you don't have to worry about pausing.

    One main issue you may have is starting to play a wma before the last has finished if you are using events to do this - they may all be trying to play at the same time.

    To be of help, we need your full code or a cut down version - something that we can run that shows the issue .  The easiest is to publish and post the code ID.
    Sunday, August 30, 2009 6:11 PM
    Moderator
  • After I put the code in, I realized it would befuddle.. so here is a pure test ..

    The WriteLines verify that the code is executed.

    'PLAY A FIRST TIME

    TextWindow.WriteLine(path+"r150.wma")
    Sound.Play(path+"r150.wma")
    Program.Delay(5000)
    'played

    TextWindow.WriteLine(path+"r155.wma")
    Sound.Play(path+"r155.wma")
    Program.Delay(5000)
    'played

    TextWindow.WriteLine(path+"r160.wma")
    Sound.Play(path+"r160.wma")
    Program.Delay(5000)
    'played

    ' NOW PLAY A SECOND TIME

    TextWindow.WriteLine(path+"r150.wma")
    Sound.Play(path+"r150.wma")
    Program.Delay(5000)
    'silence

    TextWindow.WriteLine(path+"r155.wma")
    Sound.Play(path+"r155.wma")
    Program.Delay(5000)
    'silence

    TextWindow.WriteLine(path+"r160.wma")
    Sound.Play(path+"r160.wma")
    Program.Delay(5000)
    'silence

    Interestingly, in earlier testing, I put a two second delay (shorter than the clips) in the loop and the machine actually spoke all the (first-time) clips, starting every two seconds.  It was muddled of course, but remarkable Windows allowed multiple simultaneous channels to be operating.

    Thanks!

    Dan

    Monday, August 31, 2009 1:01 PM
  • This looks like an issue I think that was raised before - sounds not rewinding after they have finished.

    If you Sound.Stop before each Sound.Play it works.

    TextWindow.WriteLine(path+"r150.wma")
    Sound.Stop(path+"r150.wma")
    Sound.Play(path+"r150.wma")
    Program.Delay(5000)

    etc.
    Monday, August 31, 2009 1:33 PM
    Moderator
  • I added the Sound.Stop .. and the code works now.

    Thanks!

    Dan
    Monday, August 31, 2009 3:40 PM