Class MusicLoader

java.lang.Object
com.badlogic.gdx.assets.loaders.AssetLoader<T,P>
com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Music,MusicLoader.MusicParameters>
edu.cornell.gdiac.assets.MusicLoader

public class MusicLoader extends com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader<com.badlogic.gdx.audio.Music,MusicLoader.MusicParameters>
This class is an AssetLoader to load Music 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 MusicQueue class instead.

  • Nested Class Summary

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

    Constructors
    Constructor
    Description
    Creates a new MusicBufferLoader with an internal file resolver
    MusicLoader(com.badlogic.gdx.assets.loaders.FileHandleResolver resolver)
    Creates a new MusicBufferLoader 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, MusicLoader.MusicParameters params)
    Returns the other assets this asset requires to be loaded first.
    protected com.badlogic.gdx.audio.Music
    Returns the Music instance currently loaded by this loader.
    void
    loadAsync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, MusicLoader.MusicParameters params)
    Loads the thread-safe part of the asset and injects any dependencies into the AssetManager.
    com.badlogic.gdx.audio.Music
    loadSync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, MusicLoader.MusicParameters 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
  • Constructor Details

    • MusicLoader

      public MusicLoader()
      Creates a new MusicBufferLoader with an internal file resolver
    • MusicLoader

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

    • getLoadedMusic

      protected com.badlogic.gdx.audio.Music getLoadedMusic()
      Returns the Music instance currently loaded by this loader. If nothing has been loaded, this returns null.
      Returns:
      the Music instance currently loaded by this loader.
    • loadAsync

      public void loadAsync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, MusicLoader.MusicParameters 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.Music,MusicLoader.MusicParameters>
      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.Music loadSync(com.badlogic.gdx.assets.AssetManager manager, String fileName, com.badlogic.gdx.files.FileHandle file, MusicLoader.MusicParameters 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.Music,MusicLoader.MusicParameters>
      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, MusicLoader.MusicParameters 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.Music,MusicLoader.MusicParameters>
      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.