Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a suspend free way of playing a sound? #19

Closed
TobseF opened this issue Mar 2, 2019 · 3 comments
Closed

Is there a suspend free way of playing a sound? #19

TobseF opened this issue Mar 2, 2019 · 3 comments

Comments

@TobseF
Copy link

TobseF commented Mar 2, 2019

I noticed that i need to load all assets inside a suspend function (eg. suspend fun VfsFile.readAudioData). But is this also necessary for playing a sound (.toNativeSound().play())? If I want to play a sound deep in my game logic, I have to make all functions on this way to a suspend function. But this seems to be even impossible if I want to trigger a sound during a KeyEvent, because the fun onKeyEvent(views: Views, event: KeyEvent) has no suspend.

So did I missed something in coroutines, korge or the KorAU API or is this the recommend way to only write suspend methods?

Btw.: The https://forum.soywiz.com seems to be down, which would be a better place for my question.
If I get it out, I could also help to improper the documentation.

@soywiz
Copy link
Member

soywiz commented Mar 2, 2019

I have fixed forum.soywiz.com already. It was not configured to start on reboot, and that's why it was down.

Typically you won't use readAudioData (unless you want to read or manipulate the data) but readNativeSound that returns a native sound ready to play. It seems that the documentation misses that part.

You would then execute the non-suspend play method that returns a NativeSoundChannel:
https://github.com/korlibs/korau/blob/c1dc966aedfe854aec9903c0ed0684b122989d04/korau/src/commonMain/kotlin/com/soywiz/korau/sound/NativeSound.kt#L81-L117

@soywiz
Copy link
Member

soywiz commented Mar 2, 2019

I have updated the documentation: korlibs-archive/docs-old.korge.org@849e9e1

@TobseF
Copy link
Author

TobseF commented Mar 2, 2019

Good hint! The doku helps a lot, so thank you for updating it👍

@soywiz soywiz closed this as completed Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants