Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
SoundChannels — Gideros Forum

SoundChannels

moopfmoopf Guru
edited October 2012 in General questions
Just a quick question on SoundChannels. I don't see any built in way to check if a SoundChannel is still playing, so are SoundChannels just destroyed once they've finished playing whatever it is they're playing?

Comments

  • MellsMells Guru
    edited October 2012 Accepted Answer
    Checking if a sound channel is playing

    On feb 29
    local channel = sound:play()
    if channel ~= nil then
        channel:addEventListener(Event.COMPLETE, function(channel)
            channel.complete = true
        end, channel)
    end
    Note : It's recommended to do a nil check on the returned SoundChannel object.
    I hope it helps.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • petecpetec Member
    Accepted Answer
    I use this format to stop channels as I exit a scene and it seems to work:
    local channel=sound:play()
    if channel then
        channel:stop()
    end
    so I guess that channel not being nil means it is playing?
  • OK, thanks for the replies. One other question, is there a way to pause a SoundChannel?
  • MellsMells Guru
    edited October 2012
    By reading this answer, it seems that @ar2rsawseen would know the solution :
    (...) you can create one Sound, and play it multiple times (creating new channel every time) and manipulate them (pause, volume, etc) separately.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • Pause (toggling) would be similar to
    Seek current position and store it somewhere
    Stop the playback
    Play/resume playback from the seek point

    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • Hi @Mells - that's interesting as there's nothing in the api documentation about pausing. You can certainly get and set the sound volume on a channel. The only way I can think of doing it is to use SoundChannel:getPosition() then stop and destroy the channel when you pause, then on resume trigger the sound to play again but specify the start sound in Sound:play(startTime,loops).

    I'll be honest, the audio API as it stands really does seem to be lacking. I know it's on one of the roadmap lists to improve it and I can't wait to see what @atilim does because currently it's bare-bones at best.

    I'm having to write an audio manager just to try and facilitate some pretty basic functionality, with a hodge-podge of the limited facilities we have currently.
  • Pause (toggling) would be similar to
    Seek current position and store it somewhere
    Stop the playback
    Play/resume playback from the seek point

    Yes, that's the only way I can think of doing it (see above which I was writing as you replied).
  • @moopf
    I came to the same conclusion as yours.
    What you suggested, also mentioned by @OZApps, is the only way that I know of.
    That's why I am intrigued to know if Arturs knows a better way.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • @Mells, no, don't know better way, but actually thats a great idea to implement into GiderosCodingEasy. I'll need to experiment more on what happens to SoundChannel ;)

    Likes: yarnee

    +1 -1 (+1 / -0 )Share on Facebook
  • Right well I kind of have the basics of my audio manager done. I've implemented music fading (using GTween to tween volume after a creating a setter and getter - @ar2rsawseen I think I originally saw that from you, thanks) so when a new track is provided the current one is faded out.

    But, even when it's faded out there's audio glitches when the track changes - sometimes it's just a click, sometimes it's actually the previous music playing briefly for half a second or so before going to the next track. This is on an iPhone 4S.

    Basically something seems a little broken.

    Likes: fxone, jimlev

    +1 -1 (+2 / -0 )Share on Facebook
  • moopfmoopf Guru
    edited October 2012
    Well I've kind of limited the issue by introducing a "fake" tween at the end of the volume fade tween that gives a 1 second gap between stopping the channel that the music is playing on and starting a new one playing. I guess things just need to catch up in the background. Although it still occasionally plays the last track at full volume for a split second before starting the track it should be. That, again, seems like an mp3 buffer still being full somewhere - whether that's Gideros or iOS I don't know. Will try on Android later and cry :)
  • More clicks and weirdness reduced by introducing a 0.2 second volume tween from 0 to required volume when a track is played. Still not perfect though.

    One question, internally in Gideros does it use hardware decoding where available (on iOS for instance) for background music?
  • MellsMells Guru
    edited October 2012
    @moopf
    Well I've kind of limited the issue by introducing a "fake" tween at the end of the volume fade tween that gives a 1 second gap between stopping the channel that the music is playing on and starting a new one playing.
    Just wondering, why don't you use a delay (in seconds, not ms) to achieve that?
    local tween2 = GTween.new(sprite, 1, {}, {autoPlay = false, delay = 1})
    local tween1 = GTween.new(sprite, 1, {}, {nextTween = tween2})
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • Hi @Mells - I'm just trying rough code at the moment to locate the issue - you're right, that can also be done how you suggest. But I think @atilim needs to weigh in on this when he's back of holidays.
  • Hi @atilim, now you're back working again when you get a moment could you comment on the issues in this thread please? Pretty please :D
Sign In or Register to comment.