(solved) Checking if a specific sound file is playing?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
llplldll
Regular
Posts: 69
Joined: Fri Aug 05, 2011 9:23 am
Completed: Memento Dears
Location: Wonderland
Contact:

(solved) Checking if a specific sound file is playing?

#1 Post by llplldll »

Im currently implementing some sound into a project Im working on.
I have a music loop that plays whenever a certain label is jumped to. The loop restarts every time I go to this label, however I don't want it to start over, if it doesn't need to.
My question is, is there a way to check if a specific sound/music is currently playing?

for example:

Code: Select all

if(musictrack1.ogg is not playing):
   play musictrack1.ogg
Im currently confused about how to express "musictrack1.ogg is not playing" in renpy
I feel like theres a "hard way" and "easy way" to do this. Ive already figured out I can just set a variable that tracks whats playing but I already have an entire project full of switching music tracks. Going through all of that won't be fun... : (
Im not very skilled at using renpy yet, as this is my first project, so I definitely think Im missing something that would be obvious to help accomplish this.

Thanks
Last edited by llplldll on Thu Jun 26, 2014 4:41 pm, edited 1 time in total.

User avatar
ArachneJericho
Regular
Posts: 196
Joined: Sun Jun 22, 2014 2:04 am
Projects: Kaguya Hime
Tumblr: mousedeerproductions
Location: Seattle, WA, USA
Contact:

Re: Checking if a specific sound file is playing?

#2 Post by ArachneJericho »

http://www.renpy.org/doc/html/audio.htm ... et_playing

There are other audio functions there. Because if conditions seem to be interpreted as python code, you should be able to use

Code: Select all

if (renpy.music.is_playing('music')): 
Edit: that only tells you if any music is playing not a specific track. :( Hmm.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Checking if a specific sound file is playing?

#3 Post by xela »

You could always create a special channel and check vs that...
Like what we're doing? Support us at:
Image

User avatar
llplldll
Regular
Posts: 69
Joined: Fri Aug 05, 2011 9:23 am
Completed: Memento Dears
Location: Wonderland
Contact:

Re: Checking if a specific sound file is playing?

#4 Post by llplldll »

ArachneJericho wrote:http://www.renpy.org/doc/html/audio.htm ... et_playing

There are other audio functions there. Because if conditions seem to be interpreted as python code, you should be able to use

Code: Select all

if (renpy.music.is_playing('music')): 
Edit: that only tells you if any music is playing not a specific track. :( Hmm.
Yeah, thats as far as I got too, lol.
I wonder if it can check the file name though?? not the channel...

xela wrote:You could always create a special channel and check vs that...
True, but all of my music tracks are playing on the same channel, the songs change automatically when "play music" is used. I have multiple scenes branching into this one label, so song changes are all over the place.
I would have to go through the entire project and stop/start music channels so that they don't play at the same time. : (

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Checking if a specific sound file is playing?

#5 Post by Alex »

Try to play your music using renpy.music.play with if_changed parameter set to True

Code: Select all

label label_name:
    $ renpy.music.play("musictrack1.ogg", loop=True, fadeout=1.0, fadein=1.0, if_changed=True)
so it should play your "musictrack1.ogg" on "music" channel and when you'll jump to this label again it should continue playing track.

http://www.renpy.org/doc/html/audio.htm ... music.play

User avatar
llplldll
Regular
Posts: 69
Joined: Fri Aug 05, 2011 9:23 am
Completed: Memento Dears
Location: Wonderland
Contact:

Re: Checking if a specific sound file is playing?

#6 Post by llplldll »

Alex wrote:Try to play your music using renpy.music.play with if_changed parameter set to True

Code: Select all

label label_name:
    $ renpy.music.play("musictrack1.ogg", loop=True, fadeout=1.0, fadein=1.0, if_changed=True)
so it should play your "musictrack1.ogg" on "music" channel and when you'll jump to this label again it should continue playing track.

http://www.renpy.org/doc/html/audio.htm ... music.play
That's exactly what Im looking for, it works!
Thank you :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot]