Class AudioPlayer


  • @Singleton
    public class AudioPlayer
    extends java.lang.Object
    General audio playback manager. Not all audio formats are supported. Refer to AudioFileFormat.Type for a list of formats supported by the sound system.
    • Constructor Summary

      Constructors 
      Constructor Description
      AudioPlayer()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void play​(java.io.File file, float gain)
      Plays an audio stream loaded from a file object.
      void play​(java.io.InputStream stream, float gain)
      Plays an audio stream from the provided input stream.
      void play​(java.lang.Class<?> c, java.lang.String path, float gain)
      Plays an audio stream loaded from a class resource.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AudioPlayer

        public AudioPlayer()
    • Method Detail

      • play

        public void play​(java.io.File file,
                         float gain)
                  throws java.io.IOException,
                         javax.sound.sampled.UnsupportedAudioFileException,
                         javax.sound.sampled.LineUnavailableException
        Plays an audio stream loaded from a file object.
        Parameters:
        file - The file object pointing to the audio data.
        gain - Gain control (in dB) to apply to audio playback.
        Throws:
        java.io.IOException
        javax.sound.sampled.UnsupportedAudioFileException
        javax.sound.sampled.LineUnavailableException
      • play

        public void play​(java.lang.Class<?> c,
                         java.lang.String path,
                         float gain)
                  throws java.io.IOException,
                         javax.sound.sampled.UnsupportedAudioFileException,
                         javax.sound.sampled.LineUnavailableException
        Plays an audio stream loaded from a class resource.
        Parameters:
        c - The class with which to load the resource.
        path - The class resource path.
        gain - Gain control (in dB) to apply to audio playback.
        Throws:
        java.io.IOException
        javax.sound.sampled.UnsupportedAudioFileException
        javax.sound.sampled.LineUnavailableException
      • play

        public void play​(java.io.InputStream stream,
                         float gain)
                  throws java.io.IOException,
                         javax.sound.sampled.UnsupportedAudioFileException,
                         javax.sound.sampled.LineUnavailableException
        Plays an audio stream from the provided input stream.
        Parameters:
        stream - The input stream containing the audio data.
        gain - Gain control (in dB) to apply to audio playback.
        Throws:
        java.io.IOException
        javax.sound.sampled.UnsupportedAudioFileException
        javax.sound.sampled.LineUnavailableException