Class PDFSound

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class PDFSound
    extends java.lang.Object
    A PDFSound represents an audio sample in a PDF document. Since 2.11.9 any audio stream that can be parsed by the Java sound subsystem can be used, however for ease of parsing we recommend PCM WAV.
    Since:
    1.1
    • Constructor Summary

      Constructors 
      Constructor Description
      PDFSound​(java.io.InputStream in)
      Create a new PDFSound from the specified InputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Object clone()  
      void close()
      Close the sound object.
      javax.sound.sampled.AudioInputStream getAudioInputStream()
      Return an AudioInputStream of this object.
      java.io.Reader getMetaData()
      Return any XML metadata associated with this object.
      int getRate()
      Return the number of samples/second this sound is played at.
      XMP getXMP()
      Return an XMP Metadata object representing any XML metadata associated with this object
      void putLiteral​(java.lang.String key, java.lang.String tokens)
      Put a literal token sequnce.
      void setMetaData​(java.lang.String xmldata)
      Set the XML metadata associated with this object.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • PDFSound

        public PDFSound​(java.io.InputStream in)
                 throws java.io.IOException

        Create a new PDFSound from the specified InputStream. The stream can be any type of Audio file that is supported by the AudioSystem, or if that system is not enabled for any reason, PCM WAV formats can be parsed directly.

        Throws:
        java.io.IOException - if the file format is invalid
    • Method Detail

      • getRate

        public int getRate()
        Return the number of samples/second this sound is played at. Common values are 8000, 11025 or 22050
        Since:
        1.1.12
      • getAudioInputStream

        public javax.sound.sampled.AudioInputStream getAudioInputStream()
        Return an AudioInputStream of this object.
        Since:
        2.11.7
      • setMetaData

        public void setMetaData​(java.lang.String xmldata)
        Set the XML metadata associated with this object. Since 2.26 this method calls getXMP().read(new StringReader(xmldata == null ? "" : xmldata)). We strongly recommend using the getXMP() method and modifying the XMP directly rather than using this method.
        Parameters:
        xmldata - the XML data to embed into the document, or null to clear any existing metadata. No validation is performed on this input.
        Since:
        1.1.12
        See Also:
        getXMP()
      • getMetaData

        public java.io.Reader getMetaData()
                                   throws java.io.IOException

        Return any XML metadata associated with this object.

        Since 2.26 this simply returns getXMP().isEmpty() ? null : new StringReader(getXMP().toString()). It is strongly recommended that any code migrates to using the getXMP() method.

        Since 2.24.3, the returned type is guaranteed to hava a toString() method that will return the Metadata as a String.

        Returns:
        a Reader containing the source of the XML or null if no metadata is available.
        Throws:
        java.io.IOException - if the metadata can't be extracted
        Since:
        1.1.12
        See Also:
        getXMP()
      • getXMP

        public XMP getXMP()
        Return an XMP Metadata object representing any XML metadata associated with this object
        Returns:
        the XMP, which may be empty or invalid but wil never be null
        Since:
        2.26
      • toString

        public java.lang.String toString()
      • close

        public void close()
        Close the sound object. This will prevent any further changes from being made to the object, but will potentially free up some resources as well.
        Since:
        2.2
      • putLiteral

        public void putLiteral​(java.lang.String key,
                               java.lang.String tokens)
        Put a literal token sequnce. For debugging
        Parameters:
        key - the key
        tokens - the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.
      • clone

        protected java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object