Ren'Py Next music button

Playstorepers

Member
May 24, 2020
160
79
TLDR Version:
1) How to determine, when only 1 or 0 songs are being played, and when a list is queued?
2) How to add a previous/Next music button (Including looped songs (aka. going from last to first song with the next button and vice versa with the previous button))?

Longass version:

Hi there everyone,

Does anyone know, how to create a previous song, next song button in the most elegant way?
I use single songs and queued songs equally often and would like to add a skip music/next/previous music button for the player, if music is ever queued

So far I have scrapped this together:

An extra screen with:

Python:
If len(renpy.music.get_loop())<2: (If you only have 1 or 0 songs playing, it only gives you a non-working "button" )
    add greyed out button previous (just an image)
    add greyed out button next (just an image)
else:
    add imagebutton previous (actual imagebutton)
    add imagebutton next (actual imagebutton)

However the len(renpy.music.get_loop()) doesn't work since get_loop doesn't seem to return something with an attribute. that len can read.

Additionally, I'm not smart enough to find the ideal solution for the actual buttons.

So far, my idea for the previous/next button would be to get the loop and then use a convoluted way (with get_playing e.g.) to get the integer of that song and then reshuffle the list with the integer as startsong and then queue it again.
It should work, but it would be just... ugly.

According to the audio-documentation, there's nothing, that I can use, unless I'm stupid (which is honestly probably the case), but the music room has a mr.Next() function, which is the thing, that I'm looking for.

Thank you all in advance.


Thanks again.

EDIT: I put the TLDR first, cuz ain't nobody got time for that
 
Last edited:

Playstorepers

Member
May 24, 2020
160
79
Bumperino.

I think, I know how to check whether there's a playlist played or not. It's quite simple, cuz I'm stupid.
There is no len, when renpy.music.get_loop() returns None.
So I just had to add another if-clause, that checks for None first.


I still don't know how to make a proper next/previous music button though.
The best I came up with was a label, that stopped the music and queued a list based on the old list, where the first song is deleted and appended on the new list. But it doesn't work, since it only works for the first song.
So I'm kinda stumped.

EDIT: 8 hours of google, documentation, filesearching and trial and error finally yielded it in the musicroom.rpy, so if someone's looking for a similar feature, there is no simple "next song"trick (like index +1/-1). You have to queue up a new queue, similar to that shit below, which i copy pasted from the musicroom:

Python:
def play(self, filename=None, offset=0, queue=False):
            """
            Starts the music room playing. The file we start playing with is
            selected in two steps.

            If `filename` is an unlocked file, we start by playing it.
            Otherwise, we start by playing the currently playing file, and if
            that doesn't exist or isn't unlocked, we start with the first file.

            We then apply `offset`. If `offset` is positive, we advance that many
            files, otherwise we go back that many files.

            If `queue` is true, the music is queued. Otherwise, it is played
            immediately.
            """

            playlist = self.unlocked_playlist(filename)

            if not playlist:
                return

            if filename is None:
                filename = renpy.music.get_playing(channel=self.channel)

            try:
                idx = playlist.index(filename)
            except ValueError:
                idx = 0

            idx = (idx + offset) % len(playlist)

            if self.single_track:
                playlist = [ playlist[idx] ]
            elif self.loop:
                playlist = playlist[idx:] + playlist[:idx]
            else:
                playlist = playlist[idx:]

            if queue:
                renpy.music.queue(playlist, channel=self.channel, loop=self.loop)
            else:
                renpy.music.play(playlist, channel=self.channel, fadeout=self.fadeout, fadein=self.fadein, loop=self.loop)
 
Last edited: