Class SoundLoader

java.lang.Object
com.badlogic.gdx.assets.loaders.AssetLoader<T,P>
com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Sound,SoundLoader.SoundParameters>
edu.cornell.gdiac.assets.SoundLoader

public class SoundLoader extends com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Sound,SoundLoader.SoundParameters>
This class is an AssetLoader to load Sound assets.

Given the primitive state of LibGDX audio, we cannot do much more than specify the filename when loading the asset. If you want more flexibility, you must use the SoundEffect class instead.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The definable parameters for a Sound object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.badlogic.gdx.assets.loaders.FileHandleResolver
    A reference to the file handle resolver (inaccessible in parent class)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new SoundBufferLoader with an internal file resolver
    SoundLoader(com.badlogic.gdx.assets.loaders.FileHandleResolver resolver)
    Creates a new SoundBufferLoader with the given file resolver
  • Method Summary

    Modifier and Type
    Method
    Description
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.assets.AssetDescriptor>
    getDependencies(String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
    Returns the other assets this asset requires to be loaded first.
    protected com.badlogic.gdx.audio.Sound
    Returns the Sound instance currently loaded by this loader.
    void
    loadAsync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
    Loads the thread-safe part of the asset and injects any dependencies into the AssetManager.
    com.badlogic.gdx.audio.Sound
    loadSync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
    Loads the main thread part of the asset.

    Methods inherited from class com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader

    unloadAsync

    Methods inherited from class com.badlogic.gdx.assets.loaders.AssetLoader

    resolve

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • resolver

      protected com.badlogic.gdx.assets.loaders.FileHandleResolver resolver
      A reference to the file handle resolver (inaccessible in parent class)
  • Constructor Details

    • SoundLoader

      public SoundLoader()
      Creates a new SoundBufferLoader with an internal file resolver
    • SoundLoader

      public SoundLoader(com.badlogic.gdx.assets.loaders.FileHandleResolver resolver)
      Creates a new SoundBufferLoader with the given file resolver
      Parameters:
      resolver - The file resolver
  • Method Details

    • getLoadedSound

      protected com.badlogic.gdx.audio.Sound getLoadedSound()
      Returns the Sound instance currently loaded by this loader.

      If nothing has been loaded, this returns null.

      Returns:
      the Sound instance currently loaded by this loader.
    • loadAsync

      public void loadAsync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
      Loads the thread-safe part of the asset and injects any dependencies into the AssetManager.

      This is used to load non-OpenGL parts of the asset that do not require the context of the main thread. As audio is thread-safe, this method does all of the work.

      Specified by:
      loadAsync in class com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Sound,SoundLoader.SoundParameters>
      Parameters:
      manager - The asset manager
      fileName - The name of the asset to load
      file - The resolved file to load
      params - The parameters to use for loading the asset
    • loadSync

      public com.badlogic.gdx.audio.Sound loadSync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
      Loads the main thread part of the asset.

      This is used to load OpenGL parts of the asset that require the context of the main thread.

      Specified by:
      loadSync in class com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Sound,SoundLoader.SoundParameters>
      Parameters:
      manager - The asset manager
      fileName - The name of the asset to load
      file - The resolved file to load
      params - The parameters to use for loading the asset
    • getDependencies

      public com.badlogic.gdx.utils.Array<com.badlogic.gdx.assets.AssetDescriptor> getDependencies(String fileName, com.badlogic.gdx.files.FileHandle file, SoundLoader.SoundParameters params)
      Returns the other assets this asset requires to be loaded first.

      This method may be called on a thread other than the GL thread. It may return null if there are no dependencies.

      Specified by:
      getDependencies in class com.badlogic.gdx.assets.loaders.AssetLoader<com.badlogic.gdx.audio.Sound,SoundLoader.SoundParameters>
      Parameters:
      fileName - The name of the asset to load
      file - The resolved file to load
      params - parameters for loading the asset
      Returns:
      the other assets this asset requires to be loaded first.