Saturday 15 February 2014

ios - Sound resource can not be loaded Swift SKAction -



ios - Sound resource can not be loaded Swift SKAction -

i have app plays sound file every time screen touched. reason, app crash every 1 time in while next error:

reason: 'resource tick.mp3 can not loaded'

in case need it, here how play file each time screen tapped:

runaction(skaction.playsoundfilenamed("tick.mp3", waitforcompletion: false))

this not happen often, maybe 1 in 10 runs of app. of time works expected. wish knew doing cause crash have no clue! tapping away seemingly no different times when doesn't crash. of sudden issue...

first of all, looks using mp3 file play (short) sound effects. when using mp3 sound compressed. in memory, have different, bigger size. there decoding performance penalty (decoding takes cpu time). of import thing, , reason why talking mp3 files can found in docs:

when using hardware-assisted decoding, device can play single instance of 1 of supported formats @ time. example, if playing stereo mp3 sound using hardware codec, sec simultaneous mp3 sound utilize software decoding. similarly, cannot simultaneously play aac , alac sound using hardware. if ipod application playing aac or mp3 sound in background, has claimed hardware codec; application plays aac, alac, , mp3 sound using software decoding.

as can see,the problem 1 mp3 file @ time can played using hardware. if play more 1 mp3 @ time, decoded software , slow.

so, recommend utilize .wav or .caf files play sound effects. mp3 background music.

about crashing issue:

try utilize .wav or .caf files instead of .mp3 try hold strong reference skaction , reuse suggested reece kenney.

ios swift sprite-kit skaction

No comments:

Post a Comment