Search code examples
sprite-kitskactionplaysound

Change duration of SKAction playSoundFileNamed


How do i change the duration of a created sound created with SKAction.playSoundFileNamed:

var sound = SKAction.playSoundFileNamed("sound.mp3", waitForCompletion: false)

I tried setting sound.duration = 1.0 but with no luck so far ?


Solution

  • In short, that is impossible with SKAction.playSoundFileNamed: method.

    duration property specifies the time in seconds required for current action to complete.

    When using SKAction.playSoundFileNamed: method you don't have control over the audio being played (no pausing, stoping, resuming pitching etc). It's meant to play a sound, nothing more.

    Some useful links:

    https://stackoverflow.com/a/22590464/3402095

    https://stackoverflow.com/a/21023417/3402095