Skip to content

Commit

Permalink
fixed a bug that causes audio service to not load properly on embedde…
Browse files Browse the repository at this point in the history
…d devices
  • Loading branch information
AlmasB committed Jul 28, 2021
1 parent 2cb4736 commit 842b079
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class AudioPlayer : EngineService() {
stopAllMusic()
}

fun loadAudio(audioType: AudioType, url: URL, isDesktop: Boolean): Audio {
return loader.loadAudio(audioType, url, isDesktop)
fun loadAudio(audioType: AudioType, url: URL, isMobile: Boolean): Audio {
return loader.loadAudio(audioType, url, isMobile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ interface AudioLoader {
* Perform an IO operation to load an audio object from [resourceURL] as a given [type].
* No caching is done by this method -- the IO operation will take place on each call.
*
* @param isDesktop if we are loading on a desktop platform
* @param isMobile if we are loading on a mobile platform
*/
fun loadAudio(type: AudioType, resourceURL: URL, isDesktop: Boolean): Audio
fun loadAudio(type: AudioType, resourceURL: URL, isMobile: Boolean): Audio

/**
* Release native resources associated with [audio].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class DesktopAndMobileAudioLoader : AudioLoader {
private val attachService by lazy { AudioService.create() }
}

override fun loadAudio(type: AudioType, resourceURL: URL, isDesktop: Boolean): Audio {
if (isDesktop) {
override fun loadAudio(type: AudioType, resourceURL: URL, isMobile: Boolean): Audio {
if (!isMobile) {
val url = resourceURL.toExternalForm()

return if (type === AudioType.MUSIC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AudioLoaderTest {

@Test
fun `Load sound file`() {
val audio = loader.loadAudio(AudioType.SOUND, javaClass.getResource("sound_effect.wav"), isDesktop = true)
val audio = loader.loadAudio(AudioType.SOUND, javaClass.getResource("sound_effect.wav"), isMobile = false)

assertThat(audio, `is`(not(getDummyAudio())))
}
Expand All @@ -39,7 +39,7 @@ class AudioLoaderTest {
@EnabledOnOs(OS.WINDOWS)
@Test
fun `Loading on mobile does not crash if Attach is not present`() {
val audio = loader.loadAudio(AudioType.SOUND, javaClass.getResource("sound_effect.wav"), isDesktop = false)
val audio = loader.loadAudio(AudioType.SOUND, javaClass.getResource("sound_effect.wav"), isMobile = true)

assertThat(audio, `is`(getDummyAudio()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class FXGLAssetLoaderService : AssetLoaderService() {
}
}

@Inject("isDesktop")
private var isDesktop = true
@Inject("isMobile")
private var isMobile = false

@Inject("userAppClass")
private lateinit var userAppClass: Class<*>
Expand All @@ -112,8 +112,8 @@ class FXGLAssetLoaderService : AssetLoaderService() {
private val cachedAssets = hashMapOf<String, Any>()

override fun onInit() {
assetData[SOUND] = SoundAssetLoader(audioService, isDesktop)
assetData[MUSIC] = MusicAssetLoader(audioService, isDesktop)
assetData[SOUND] = SoundAssetLoader(audioService, isMobile)
assetData[MUSIC] = MusicAssetLoader(audioService, isMobile)

log.debug("User app class for loading assets: $userAppClass")
}
Expand Down Expand Up @@ -674,20 +674,20 @@ private class ResizableImageAssetLoader : AssetLoader<Image>(
override fun getDummy(): Image = getDummyImage()
}

private class SoundAssetLoader(val audioService: AudioPlayer, val isDesktop: Boolean) : AssetLoader<Sound>(
private class SoundAssetLoader(val audioService: AudioPlayer, val isMobile: Boolean) : AssetLoader<Sound>(
Sound::class.java,
SOUNDS_DIR
) {
override fun load(url: URL): Sound = Sound(audioService.loadAudio(AudioType.SOUND, url, isDesktop))
override fun load(url: URL): Sound = Sound(audioService.loadAudio(AudioType.SOUND, url, isMobile))

override fun getDummy(): Sound = Sound(getDummyAudio())
}

private class MusicAssetLoader(val audioService: AudioPlayer, val isDesktop: Boolean) : AssetLoader<Music>(
private class MusicAssetLoader(val audioService: AudioPlayer, val isMobile: Boolean) : AssetLoader<Music>(
Music::class.java,
MUSIC_DIR
) {
override fun load(url: URL): Music = Music(audioService.loadAudio(AudioType.MUSIC, url, isDesktop))
override fun load(url: URL): Music = Music(audioService.loadAudio(AudioType.MUSIC, url, isMobile))

override fun getDummy(): Music = Music(getDummyAudio())
}
Expand Down

0 comments on commit 842b079

Please sign in to comment.