public class

SoundAnnotation

extends Annotation
java.lang.Object
   ↳ com.pspdfkit.annotations.Annotation
     ↳ com.pspdfkit.annotations.SoundAnnotation

Class Overview

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.

Summary

Nested Classes
@interface SoundAnnotation.IconName Denotes possible constants for sound annotation icons. 
Constants
String ICON_NAME_MIC Icon name for the microphone icon of sound annotations.
String ICON_NAME_SPEAKER Icon name for the speaker icon of sound annotations.
[Expand]
Inherited Constants
From class com.pspdfkit.annotations.Annotation
[Expand]
Inherited Fields
From class com.pspdfkit.annotations.Annotation
Public Constructors
SoundAnnotation(int pageIndex, RectF boundingBox, EmbeddedAudioSource audioSource)
Creates a new sound annotation.
SoundAnnotation(int pageIndex, RectF boundingBox)
Creates a new sound annotation.
Public Methods
byte[] getAudioData()
Returns audio data from the annotation.
Maybe<byte[]> getAudioDataAsync()
Returns audio data from the annotation, asynchronously.
AudioEncoding getAudioEncoding()
Encoding of the audio data.
int getChannels()
The number of audio channels.
String getIconName()
Returns the name of the icon that should be displayed for this annotation.
int getSampleRate()
The number of audio samples for each channel per second.
int getSampleSize()
The number of bits per sample value per channel.
AnnotationType getType()
Gets the annotation type of the annotation.
boolean hasAudioData()
Checks if the annotation contains valid audio data in supported encoding.
boolean isLocked()
Check if the annotation is locked - i.e.
boolean isResizable()
Check if the annotation is resizable, or if this is a non-resizable annotation.
void setAudioSource(EmbeddedAudioSource soundSource)
Replaces the audio data in this annotation.
void setIconName(String iconName)
Sets the name of the icon that should be displayed for this annotation.
void updateTransformationProperties(RectF newBoundingBox, RectF oldBoundingBox)
Annotations may override this method to transform their properties (i.e.
[Expand]
Inherited Methods
From class com.pspdfkit.annotations.Annotation
From class java.lang.Object

Constants

public static final String ICON_NAME_MIC

Icon name for the microphone icon of sound annotations.

Constant Value: "Mic"

public static final String ICON_NAME_SPEAKER

Icon name for the speaker icon of sound annotations.

Constant Value: "Speaker"

Public Constructors

public 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.

public 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.

Public Methods

public 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.

public Maybe<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.

public AudioEncoding getAudioEncoding ()

Encoding of the audio data.

Returns
  • Encoding used for audio data samples.

public int getChannels ()

The number of audio channels.

Returns
  • Number of channels in the audio data.

public String getIconName ()

Returns the name of the icon that should be displayed for this annotation.

Returns
  • Icon name, {@value ICON_NAME_SPEAKER} by default.

public int getSampleRate ()

The number of audio samples for each channel per second.

Returns
  • Sampling rate of the audio data in Hz.

public 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.

public AnnotationType getType ()

Gets the annotation type of the annotation.

Returns
  • The type of the annotation. Makes down casting easier.

public 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.

public 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.

public 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).

public void setAudioSource (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(String)). If the description is null, the original contents will be kept.

Parameters
soundSource Source for the embedded sound data.

public void setIconName (String iconName)

Sets the name of the icon that should be displayed for this annotation.

Parameters
iconName Icon name to be set.

public void updateTransformationProperties (RectF newBoundingBox, 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).