Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Start playing mp3 sound instantly on Android — Gideros Forum

Start playing mp3 sound instantly on Android

totebototebo Member
edited August 2016 in General questions
To avoid a slight pause before playing an mp3 file I'm doing this:

1. Create sound channel
2. Pause sound channel
3. Unpause sound channel when the mp3 needs playing

Even though the channel is in memory, there is still a pause before the sound starts playing (the game freezes for a short while).

Is there a way of playing an mp3 file without freezing the game?

My Gideros games: www.totebo.com

Comments

  • Update:

    This has removed the issue, but the mp3 now fails to play seemingly randomly:

    1. Create sound channel
    2. Keep playing sound channel, set volume to 0
    3. Set volume to 1 when the mp3 needs playing

    I'm using less than 32 channels, so any ideas why this method wouldn't work would be warmly received.
    My Gideros games: www.totebo.com
  • With your issue and randomly not working.. Does it fail randomly when you set the volume?

    There is a strange bug (I have to call it a bug because it needs to be fixed) where after playing the mp3 once, it just stops and does not loop. The only solution is to have an event listener that waits for the end of the song, and then restarts it. This is what (for me) causes the horrible gaps in playing.

    So I'm wondering if your issue might be caused by the mp3 reaching the end and then not looping, so when you set the volume to 1, it seems as if it has not played at all. I hope that makes sense ;)
  • In Android this is the latency because we use openal, I think that a move should be made to opensl es (if it's available) with a fallback to openal. Opensl es has lower latency.

    Likes: totebo, antix

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • totebototebo Member
    edited August 2016
    @antix, no this is unrelated to volume changes. I'm patching the loop issue by creating a new channel when a sound has finished (if set to loop). This itself causes a delay in the sound repeating, but it doesn't freeze the game. It would be lovely to see looping working well on Android, but this is a lesser problem in my case.

    @sinistersoft, if opensl would solve this, or reduce the time it takes to play an mp3, I am very much for it.
    My Gideros games: www.totebo.com
  • @SinisterSoft please! That would be very cool. Having looping music that doesn;t loop correctly is really not good.

    @totebo, interesting. If there was some way to tell how long the delay would be.. then you could time the creation of the new sound channel, hmm.

    So does creating a new sound channel perform better than just restarting it and creating a new event listener?
  • hgy29hgy29 Maintainer
    Wait, wait, wait... you are on Android and playing MP3 right ? in that case OpenAL isn't used, MP3 is played through android's MediaPlayer class!
  • I have not encountered this issue in any other application besides a Gideros one so didn't think android its self might be the issue.
  • @hgy29, yeah Android only.
    My Gideros games: www.totebo.com
  • totebototebo Member
    edited August 2016
    I've managed to get the lag down considerably with this class. Each sound has to be added with addSound() before it can be used. It includes the fix for looping sounds.

    This is fast on Android, still laggy on iOS. May need to have a special case for iOS.
    lua
    lua
    Sounds.lua
    2K

    Likes: antix

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    edited August 2016
    If you have a large number of sound effects then playing them all will really chew up audio resources. On Android at least this can cause some issues since there is a fairly meager limit on how many sounds can play at once. Your method works though :)

    I think sound in Gideros really needs a bit of attention.
    +1 -1 (+2 / -0 )Share on Facebook
  • spam...
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Everytime I use the sound zone, and change the script to music.lau or what ever it just freezes up, then I have to create a random object and click properties to get out the property tab. What should I do?
  • If you suspect the issue occurred after Windows updates, I would request you to perform a System Restore prior to the installation of Windows updates and then check if it helps.
    get free ringtones download for mobiles
Sign In or Register to comment.