License from €75 Log in
DE EN FR ES IT CZ

Background music

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 12 years ago
    Hi,

    i have music on background in one scene and the thing is that everytime i leave the scene and come back again the music is playing from the beginning, which is a bit disturbing,
    is it possible to start the music from random position?

    thanks
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 12 years ago
    Only if you use the lua sound functions to start / stop / pause audio files. The files have to be loaded & controlled via Lua script to be able to use the openAL audio functions. Sounds started via the editor or via action parts can't be edited by Lua.

    Check out the various sound functions via this page.
  4. · 12 years ago
    Guess something like this should work, but the sound is playing about 0.1 second only ( from the beginning )
    The folder podklady is in the same folder as Vis file.

    local soundID = getSoundId("vispath:podklady/Hudba/hotel/party.ogg")
    local soundOffset = getSoundProperty(soundID, "offset")
    startSound("vispath:podklady/Hudba/hotel/party.ogg", {flags=1, volume=40, offset=math.random(0, soundOffset) })
    


    Edit: i changed "offset" to "duration" and still the same.
  5. · 12 years ago
    Offset is the current playtime position. You want to use the duration property for the getSoundProperty() function.
    local soundOffset = getSoundProperty(soundID, "duration")
    


    P.S: you don't have to add 0, to the math.random function. By default if you only enter 1 value, then it will automatically return a number between 0 & the number you specified. The min number only has to be set if you want the min number to be something other than 0; say -10 or 22 for example.
  6. · 12 years ago
    Thanks, i used the duration property, but it's the same result.
    So i tried to just play the sound without any properties and it still plays the sound just for a few ms.

    Okej, got it :-)
  7. · 12 years ago
    Ah you mean it's not playing the entire track? Try adding loop = true parameter. Also not 100% sure but I think you aren't actually generating the soundID. I think you need to use the getSoundId() function & that the sound needs to be playing to return an id.

    If you know the duration of the track in seconds then just google: "convert seconds to ms" & it will display a unit converter for time. Just enter in time in seconds or minutes to convert to milliseconds then add that to your math.random() number.

    http://www.checkyourmath.com/convert/time/milliseconds_secon...

    The math is pretty simple anyway...

    * seconds to milliseconds: seconds x 1000
    * milliseconds to seconds: milliseconds ÷ 1000

    120s = 120,000 milliseconds.
  8. · 12 years ago
    Yeah i was just thinking how to do it more dynamically...
    It starts play the sound and after a few ms it stops.

    Current, without the first part:
    startSound("vispath:podklady/Hudba/hotel/party.ogg", {flags=1, volume=40, loop=true, offset=math.random(76000) })
    


    but nothing confuse
  9. · 12 years ago
    Are there any errors listed in the log file after executing the startSound() function?
  10. · 12 years ago
    Nope, no errors.
    btw what the flags=1 means?
  11. · 12 years ago
    To be honest, I'm not really sure. grin
    I think it's just something that tells the engine that it should also update the table for the specified object / function with the included parameters.

    There are a few functions that seem to include the flags=1 thing.
  12. · 12 years ago
    Hehe,

    anyway it's strange, i tried different file and path too and still the same, i'll leave it for now and get back to it later..
    Thanks

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?