×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    5

    Question Play one sound after another

    Hi everyone

    I've started to learn Python a few days ago, I'm using the useful aXYZ module (thanks cyke64 to trigger sounds based on phone change of position. Anyway, it seems difficult to me to play two sounds one after another.

    This is the code I'm using (taken from one tutorial)

    Code:
    s = audio.Sound.open(path1)
    s.play()
    s = audio.Sound.open(path2)
    s.play()
    s.close()
    Since this is within a function that is called several times a second (its called from the read(x, y, z) that triggers the aXYZ module, it starts to play the first file and immediately stops and starts to play the second and stops (I suppose due to the s.close()

    I would like to know how to play an entire sound and then start to play the other sound, looks like s.play() is asynchronous, it doesnt "wait" for the file to completely play before to start with the new one.

    Is there any way to do this or I'll have to embed the play function inside a while loop and then constantly ask if the file is finished played?

  2. #2
    Registered User
    Join Date
    Aug 2008
    Location
    Varna, Bulgaria
    Posts
    16

    Re: Play one sound after another

    Try this:
    Code:
    s = audio.Sound.open(path1)
    s.play()
    while s.state()==audio.EPlaying:
     #empty while
    s = audio.Sound.open(path2)
    ...
    I'm not sure if this particular snippet will work, but that's the general idea.

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,779

    Re: Play one sound after another

    Quote Originally Posted by remoto View Post
    Anyway, it seems difficult to me to play two sounds one after another.
    Hi Remoto and Welcome to PyS60 !

    The problem with your code is that you are not calling the s.stop() before starting a new play function

    stop()
    Stops playback or recording of an audio file.


    When you need to play a file it should be like this :
    Code:
    s = audio.Sound.open(path1)
    s.play()
    s.stop()
    #Now you can try to play other path below this :)
    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    158

    Re: Play one sound after another

    can we pause sound?

  5. #5
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,779

    Re: Play one sound after another

    Quote Originally Posted by cool_eagle View Post
    can we pause sound?
    Hi Mr. Eagle,

    Yes, you can pause a sound in PyS60. However there is no straight forward function for it like play() and stop()

    Here is how you can pause :

    1) When a Pause is to be executed : stop the sound by stop() and use a timer to record the time at which it is stopped in a variable.

    Now your sound is paused (actually it is stopped)

    But you have recorded the time so you can begin to play from their, when resuming.

    2) Use the following function :

    set position(microseconds) : Set the position for the playhead.

    3) Use the play function : play() [This will resume from where is had stopped]

    Hope that helps,

    Best Regards,
    Croozeus
    Last edited by croozeus; 2008-08-28 at 20:29.
    Pankaj Nathani
    www.croozeus.com

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    5

    Re: Play one sound after another

    Quote Originally Posted by cshtarkov View Post
    Try this:
    Code:
    s = audio.Sound.open(path1)
    s.play()
    while s.state()==audio.EPlaying:
     #empty while
    s = audio.Sound.open(path2)
    ...
    I'm not sure if this particular snippet will work, but that's the general idea.
    Thanks! That's what I though at first, however it seems that EPlaying is not responding acordingly, so I've used this:

    Code:
    s.play()
    while.state()==2:
      sleep(0.1)
    s.stop()
    s.close()
    I have still the same problem, when you call .play() Symbian starts to play the sound and then the code continues to run, it doesn't wait to the file finished playing!

    Since I'm using this from aXYZ the same sound file is called several times a second, I need to play one file, stop code execution untill the file is totally played and then continue executing code

    I've tried to use a global variable declared at the body of the python code but I dont know how to use that inside a function, it says that I'm trying to use it before declare it.

    I'm trying to follow this logic:
    - aXYZ triggers (several times a second) a function based on device change of position
    - Play sound file
    - Wait for the whole file to be played
    - Continue to wait for new device movement

    What happens?
    - aXYZ triggers the function
    - The sound file is being played
    - If I move the phone at this moment then the function is triggered again and the file is played one more time I want to disable this untill the whole sound file is being played
    - I would like to use a global variable to achieve this, a variable that holds the "state" of "beingplayed" and then changes to "readytoplay", however I can not use this since I cannot use it from inside a function, any ideas?

    Thanks for your help!

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Play one sound after another

    Quote Originally Posted by remoto View Post
    I've tried to use a global variable declared at the body of the python code but I dont know how to use that inside a function, it says that I'm trying to use it before declare it.
    hi remoto
    i think article may help you a bit.

    Enjoy Pythoning
    Gaba88

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Play one sound after another

    I suggest trying e32.ao_sleep() instead of time.sleep() in the loop.

Similar Threads

  1. use CMdaAudioPlayerUtility play sound
    By HellenZ in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2010-02-22, 15:15
  2. Cannot play mid and wav sound at the same time on Nokia N96.
    By Ishnu_Blue in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2008-08-26, 11:14
  3. sound bug (possibly) on 6610
    By alex_crowther in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-02-05, 11:44
  4. Nokia Smart Expert - solve this sound problem
    By tsoh_tan in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2003-10-30, 04:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •