How to get orxSOUND_EVENT_STOP for music?

edited November 2017 in Help request
I'm adding some music to my game, and I want to detect when a music track ends. (So another one can be started from code)

I followed the sounds tutorial, and created a sound event handler, with
orxEvent_AddHandler(orxEVENT_TYPE_SOUND, EventHandler);
The event handler works, but I only get orxSOUND_EVENT_PACKET events for my musics, and no other events. There is only a orxSOUND_EVENT_PACKET in _pstEvent->eID. When the music ends, there is no orxSOUND_EVENT_STOP.


How can I detect when a music track ends, if not with the STOP event ?

(I'm creating the musics from config, using orxSound_CreateFromConfig() and starting them with orxSound_Play(). The tracks are set to Loop = false. I'm testing it on android.)

Comments

  • edited November 2017
    I worked around it, by checking if I get any PACKET events for the music within the last 1 second. And if not, it generates a custom stop event. That's fine for changing music tracks...
  • edited November 2017
    Hi!

    Sorry for the late reply.

    So you can indeed rely on the stop event... if you're using an object, which I recommend.

    in config you'd have:
    [MusicObject]
    SoundList = MyMusic
    
    [MyMusic]
    Music = mymusicfile.ogg
    
    and in code:
    orxObject_CreateFromConfig("MusicObject");
    

    Of course that object can then be manipulated like any other objects, including pause, disable, lifetime and even time stretching (which will affect the pitch of the sounds/musics played on it).
  • edited November 2017
    Sorry, had to edit my post as the config part was erroneous!
  • edited November 2017
    Hi iarwain!

    Thanks for the info!

    OK, I'll check out how to use a music object.

    Suppose I have multiple music tracks in the music object's SoundList. Such as:
    [MusicObject] 
    SoundList = music1 # music2 # music3 
     
    [music1] 
    Music = music1.ogg 
    Loop = false
    
    [music2] 
    Music = music2.ogg 
    Loop = false
    
    [music3] 
    Music = music3.ogg 
    Loop = false
    

    How can I play a specific sound from these ? (This wasn't described in the tutorial... I'm playing the sounds now directly with orxSound_Play(). Not sure how to do it with a music object.)
  • edited November 2017
    If you have multiple sounds, they'll all play at once.

    You can use orxObject_AddSound/orxObject_RemoveSound to add/remove sounds and music on an object. (You can also use play/pause if needed.)
    Or you could simply delete that object and create a new one.
    [Music1]
    SoundList = @
    Music = music1.ogg
    
    [Music2]
    SoundList = @
    Music = music2.ogg
    
    [Music3]
    SoundList = @
    Music = music3.ogg
    

    This has the advantage that it's easy to create/delete not only from code but also from config using tracks/commands.
  • edited November 2017
    Wow, this looks like an elegant solution. To have one separate music object for each track, and just delete/create them as needed.

    If it works with the STOP event, that's probably the best way to do it. Thanks!
  • edited November 2017
    Glad you like it!
    Most of the time, users only need to interface with the orxObject API without needing to dive into the various components that can be bound to an object. That includes sound/music but also spawners (useful for FXs), shaders, etc...
Sign In or Register to comment.