Music Position

Monkey Forums/Monkey Programming/Music Position

smilertoo(Posted 2012) [#1]
Does monkey have any commands to set the play position in a music/sound file? eg...i walk into a spooky woods and i want to jump to the spooky segment of my tune.


Anatol(Posted 2012) [#2]
I don't think this is currently possible with Monkey. It seems audio is handled quite different on the various targets, and most Monkey functionality is limited to the "lowest common denominator" (if that's the right expression to use).

You may be able to add the target specific code directly into the translated code or write your own target, but I don't think it's very straightforward. So far I've avoided to go into that direction and tried to find workarounds in Monkey.

Is this one long music file with different (happy/spooky/surprise etc.) segments that go seamlessly from one to another? Or could you use separate sound files and crossfade them via Monkey code?

I'm also still hoping for some improvements to the audio module. I would love the ChannelState() function to work for Android for example. And I agree something like a SetSoundPosition(sound:Sound, millisecs%) and SetMusicPosition(music:Music, millisecs%) would be great.

Another audio functionality on my wishlist would be at least two music channels for streaming audio (so I can fade background music from one to another and am not limited to 1MB audio files on Android).


therevills(Posted 2012) [#3]
Samah added SeekMusic to Diddy for his Storyboard module and it works for most targets, only XNA and PSM isnt supported.


Cygnus(Posted 2012) [#4]
@therevills, that's neat!

@Smilertoo, I handled this by exporting my music in segments and looping in code. I'll go into a bit more detail than you need because it may help.

(you need a high update rate so wrap OnUpdate and OnRender so it doesn't run fast) By playing the same sample on channel 0, then after it plays its last bar starting it on channel 1, then back to channel 0, I was able to loop flawlessly (no clicking) - this requires your audio samples don't "cut off" at the end though- let it fade naturally and keep track of the number of bars in each snippet in code instead of just checking the channel stopped playing. call StopChannel() before Play()ing anything because that doesn't crash, but Play()ing on a channel that is already in use does.


Supertino(Posted 2012) [#5]
@ Cygnus - I am going to give this a whirl today