Orx - Portable Game Engine
Welcome, Guest
Please Login or Register.    Lost Password?
How to get orxSOUND_EVENT_STOP for music?
(1 viewing) 1 Guest
Go to bottom
TOPIC: How to get orxSOUND_EVENT_STOP for music?
#8820
rgdev
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 0
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
Code:


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.)
 
Logged Logged
  The administrator has disabled public write access.
#8821
rgdev
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 0
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...
 
Logged Logged
  The administrator has disabled public write access.
#8822
iarwain
Administrator
Posts: 3129
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 71
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:
Code:


[MusicObject]
SoundList = MyMusic

[MyMusic]
Music = mymusicfile.ogg


and in code:
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).
 
Logged Logged
 
Last Edit: 2017/11/29 17:07 By iarwain.
 
Want to follow orx's development? Check our Trello board: http://trello.com/b/g4jMS6jc/orx-tasks
  The administrator has disabled public write access.
#8823
iarwain
Administrator
Posts: 3129
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 71
Sorry, had to edit my post as the config part was erroneous!
 
Logged Logged
 
Want to follow orx's development? Check our Trello board: http://trello.com/b/g4jMS6jc/orx-tasks
  The administrator has disabled public write access.
#8824
rgdev
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 0
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:

Code:


[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.)
 
Logged Logged
  The administrator has disabled public write access.
#8825
iarwain
Administrator
Posts: 3129
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 71
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.

Code:


[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.
 
Logged Logged
 
Last Edit: 2017/11/29 17:51 By iarwain.
 
Want to follow orx's development? Check our Trello board: http://trello.com/b/g4jMS6jc/orx-tasks
  The administrator has disabled public write access.
#8826
rgdev
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 0
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!
 
Logged Logged
  The administrator has disabled public write access.
#8827
iarwain
Administrator
Posts: 3129
graph
User Offline Click here to see the profile of this user
Gender: Male Orx - Portable Game Engine Location: Montreal
Re:How to get orxSOUND_EVENT_STOP for music? 2 Weeks, 4 Days ago Karma: 71
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...
 
Logged Logged
 
Want to follow orx's development? Check our Trello board: http://trello.com/b/g4jMS6jc/orx-tasks
  The administrator has disabled public write access.
Go to top