Class SoundAnnotation

  • All Implemented Interfaces:

    
    public class SoundAnnotation
    extends Annotation
                        

    Represents an audio file added to a page. Sound annotations can be created from recording audio using the device's microphone or by importing an existing audio file. Sound annotations are stored inside the PDF file itself. On a page, SoundAnnotations are represented by an icon, similar to NoteAnnotations. PSPDFKit will always render sound annotations at a fixed size, centered in the provided boundingBox.

    • Constructor Detail

      • SoundAnnotation

        SoundAnnotation(int pageIndex, RectF boundingBox, EmbeddedAudioSource audioSource)
        Creates a new sound annotation.
        Parameters:
        pageIndex - Page to which this annotation will be attached to.
        boundingBox - Annotation's bounding box on the page in PDF coordinates.
        audioSource - Source of audio data that should be attached to the annotation.
      • SoundAnnotation

        SoundAnnotation(int pageIndex, RectF boundingBox)
        Creates a new sound annotation.
        Parameters:
        pageIndex - Page to which this annotation will be attached to.
        boundingBox - Annotation's bounding box on the page in PDF coordinates.
      • SoundAnnotation

        SoundAnnotation(AnnotationPropertyManager properties, boolean markDirty, String resourceId)
        Intended for internal usage only
      • SoundAnnotation

        SoundAnnotation(AnnotationPropertyManager propertyMap, boolean markDirty, EmbeddedAudioSource soundData)
        Intended for internal usage only
    • Method Detail

      • setAudioSource

         void setAudioSource(@Nullable() EmbeddedAudioSource soundSource)

        Replaces the audio data in this annotation.

        If the getDescription is not-null, it will be set as new annotation contents (via setContents). If the description is null, the original contents will be kept.

        Parameters:
        soundSource - Source for the embedded sound data.
      • getSampleSize

         int getSampleSize()

        The number of bits per sample value per channel. 8 or 16 bits per channel are supported.

        Returns:

        Number of bits per sample value in the audio data.

      • getSampleRate

         int getSampleRate()

        The number of audio samples for each channel per second.

        Returns:

        Sampling rate of the audio data in Hz.

      • getChannels

         int getChannels()

        The number of audio channels.

        Returns:

        Number of channels in the audio data.

      • hasAudioData

         boolean hasAudioData()

        Checks if the annotation contains valid audio data in supported encoding.

        Returns:

        true when sound annotation is attached to the document and contains audio data.

      • getAudioData

        @Nullable() Array<byte> getAudioData()

        Returns audio data from the annotation. This could take a while and should be executed on background thread.

        Returns:

        Byte array with raw audio data in getAudioEncoding encoding and Big-endian byte order. Returns null if audio data could not be read or the annotation is not attached to the document.

      • getAudioDataAsync

        @NonNull() Maybe<Array<byte>> getAudioDataAsync()

        Returns audio data from the annotation, asynchronously.

        Returns:

        Maybe emitting byte array with raw audio data with getAudioEncoding encoding and Big-endian byte order. Empty/error events are emitted when audio data could not be read or the annotation is not attached to the document.

      • getType

        @NonNull() AnnotationType getType()

        Gets the annotation type of the annotation.

        Returns:

        The type of the annotation. Makes down casting easier.

      • updateTransformationProperties

         void updateTransformationProperties(@NonNull() RectF newBoundingBox, @NonNull() RectF oldBoundingBox)

        Annotations may override this method to transform their properties (i.e. points, rects, sizes) whenever the bounding box of the annotation changed.

        Parameters:
        newBoundingBox - New bounding box of the annotation (in PDF points).
        oldBoundingBox - Old bounding box of the annotation (in PDF points).
      • isResizable

         boolean isResizable()

        Check if the annotation is resizable, or if this is a non-resizable annotation.

        Returns:

        true if the annotation can be resized (e.g. ink annotation) or false if it is a non-resizable one (e.g. note annotation).

      • isLocked

         boolean isLocked()

        Check if the annotation is locked - i.e. annotation can't be deleted or modified (except contents).

        Returns:

        true if the annotation is locked or false if it can be freely modified.