Sound for Scene Transition, That Doesn't Stutter

Sound for Scene Transition, that doesn't stutter

As crashoverride777 said, you need to change when you load the sound manager. You could set up a thread in your didMoveToView() function to minimize loading time:

DispatchQueue.global(qos: .userInitiated).async {
// Load your sound stuff
}

Now, you have your sound file loaded for whenever you need it, lag-free.

Can I use an ended sound file to transition to a new scene or refresh data in the same scene?

What you can do is create a function listener for the first audio file you can look more here: https://docs.coronalabs.com/api/library/audio/play.html Below is a sample code I can give you. Note that I did not use audio.stopWithDelay

--DECLARE LOCAL VARIABLES
local visual1
local visual2
local music1
local music2

--LOAD SOUNDS
music1 = audio.loadStream("sound1.mp3")
music2 = audio.loadStream("sound2.mp3")

local function soundIsFinished(event)

if (event.completed) then

--PLAY SECOND AUDIO AND HIDE/REMOVE VISUAL 1
visual1.isVisible = false
visual2.isVisible = true
audio.play(music2, {duration = 1000})

end

end

--DISPLAY VISUAL1 and play MUSIC1
visual1 = display.newImage("redCircle.png", 50,50)

--AUDIO WILL PLAY FOR 1 SECOND (60000/60) is 1 second
audio.play(music1, { duration=1000, onComplete=soundIsFinshed } )

-- HIDE VISUAL2 FIRST
visual2 = display.newImage("blueCircle.png", 50,50)
visual2.isVisible = false

Hope This helps.

Adding sound to spritekitgame upon gameover transition

What you could do here is to use completion block.

For example:

Define one:

typedef void (^CompletionBlock)();

- (void)playSoundWhenMonsterHitsGround:(CompletionBlock)completionBlock
{
[self.monster runAction:self.gameoverSound];
completionBlock();
}

And in your -(void)monster:(SKSpriteNode *)monster didCollideWithbottomGround:(SKSpriteNode *)bottomGround:

-(void)monster:(SKSpriteNode *)monster didCollideWithbottomGround:(SKSpriteNode *)bottomGround 
{
[self resetDuration];
[_monster removeFromParent];
[self playSoundWhenMonsterHitsGround:^
{
SKTransition *reveal5 = [SKTransition fadeWithDuration:0.5];
SKScene * InstructionSceneL = [[GameOverScene alloc] initWithSize:self.size score:player_score];
InstructionSceneL.scaleMode = SKSceneScaleModeAspectFill;
[self.view presentScene:InstructionSceneL transition:reveal5];
}];
}

Hope this helps.

Loading screens in games (ensuring animations don't stutter during the transition)

You diagnosed it correctly yourself, although it's not CCSpriteFrameCache that's being dealloced but the CCTextureCache it relies on.

If you created your project from the default cocos2d template, your app delegate responds to applicationDidReceiveMemoryWarning by calling [[CCDirector sharedDirector] purgeCachedData]. This in turn calls [CCTextureCache purgeSharedTextureCache], which releases and nils out the shared cache. That happens on your main app thread, and since your background thread is in the middle of using that same cache to store the textures it's loading... boom.

The simplest fix is just to remove that purgeCachedData call from your app delegate. You understand your app's memory consumption better than the OS does, so rather than let the OS tell you when to purge your cache, do it yourself: Call purgeCachedData only when you know you have textures cached that you won't be using anymore.

From your brief description, it sounds like you would do that at the start of your transition/loading scene. Just be sure to do the purge after you create the sprites you use for your progress animation, so that their textures are kept around. (The purge call doesn't delete anything that's currently in use.) Likewise, be sure to do the purge before you kick off your background thread, or else you'll get the same crash you're seeing now.

Cannot stop background music from within Game Scenes, Swift 3/Spritekit

Why not create a music helper class that you can access from anywhere. Either the singleton way or a class with static methods. This should also make your code cleaner and easier to manage.

I would also split the setup method and the play method so that you do not set up the player each time you play the file.

e.g Singleton

class MusicManager {

static let shared = MusicManager()

var audioPlayer = AVAudioPlayer()

private init() { } // private singleton init

func setup() {
do {
audioPlayer = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "music", ofType: "mp3")!))
audioPlayer.prepareToPlay()

} catch {
print (error)
}
}

func play() {
audioPlayer.play()
}

func stop() {
audioPlayer.stop()
audioPlayer.currentTime = 0 // I usually reset the song when I stop it. To pause it create another method and call the pause() method on the audioPlayer.
audioPlayer.prepareToPlay()
}
}

When your project launches just call the setup method

MusicManager.shared.setup()

Than from any where in your project you can say

MusicManager.shared.play()

to play the music.

To than stop it just call the stop method

MusicManager.shared.stop()

For a more feature rich example with multiple tracks check out my helper on GitHub

https://github.com/crashoverride777/SwiftyMusic

Hope this helps

Speech Synthesis on iOS weird errors on loading, and no concurrency

As for #1, it's probably not gonna happen. The speech synthesizer is a system shared resource, so how the system handles scheduling multiple requests is out of our control as clients of the API. (Note that if you reuse the same synthesizer, it queues up extra utterances, but if you create multiple synthesizers, it fails to speak utterances that are requested while another synthesizer is speaking.)

Dunno about #2, sorry. Looks like diagnostic text, not necessarily an error. Probably worth filing a bug about, since they probably don't want to be logging diagnostics when there's no actual problem.

Bonus answer: You can use functional programming to make the selection of voice a bit shorter:

let voice = AVSpeechSynthesisVoice.speechVoices().first(where: { $0.name == "Arthur" })

What is a good format for storing sounds on windows compressed?

While WAV files are typically uncompressed, they can be compressed with various codecs and still be played with the system API's. The largest factors in the overall size are the number of channels (mono or stereo), the sample rate (11k, 44.1k, etc), and the sample size (8 bit, 16 bit, 24 bit). This link discusses the various compression schemes supported for WAV files and associated file sizes:

http://en.wikipedia.org/wiki/WAV

Beyond that, you could resort to encoding the data to WMA files, which are also richly supported without third party libraries, but would probably require using the Windows Media SDK or DirectShow for playback.

This article discusses the WMA codecs and levels of compression that can be expected:

http://www.microsoft.com/windows/windowsmedia/forpros/codecs/audio.aspx



Related Topics



Leave a reply



Submit