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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interface
SoundAnnotation.IconName
Denotes possible constants for sound annotation icons.
-
Field Summary
Fields Modifier and Type Field Description public final static String
ICON_NAME_SPEAKER
public final static String
ICON_NAME_MIC
-
Constructor Summary
Constructors Constructor Description SoundAnnotation(int pageIndex, RectF boundingBox, EmbeddedAudioSource audioSource)
Creates a new sound annotation. SoundAnnotation(int pageIndex, RectF boundingBox)
Creates a new sound annotation. SoundAnnotation(AnnotationPropertyManager properties, boolean markDirty, String resourceId)
Intended for internal usage only SoundAnnotation(AnnotationPropertyManager propertyMap, boolean markDirty, EmbeddedAudioSource soundData)
Intended for internal usage only
-
Method Summary
Modifier and Type Method Description void
setAudioSource(@Nullable() EmbeddedAudioSource soundSource)
Replaces the audio data in this annotation. int
getSampleSize()
The number of bits per sample value per channel. int
getSampleRate()
The number of audio samples for each channel per second. int
getChannels()
The number of audio channels. AudioEncoding
getAudioEncoding()
Encoding of the audio data. boolean
hasAudioData()
Checks if the annotation contains valid audio data in supported encoding. Array<byte>
getAudioData()
Returns audio data from the annotation. Maybe<Array<byte>>
getAudioDataAsync()
Returns audio data from the annotation, asynchronously. String
getIconName()
Returns the name of the icon that should be displayed for this annotation. void
setIconName(@SoundAnnotation.IconName() String iconName)
Sets the name of the icon that should be displayed for this annotation. AnnotationType
getType()
Gets the annotation type of the annotation. void
updateTransformationProperties(@NonNull() RectF newBoundingBox, @NonNull() RectF oldBoundingBox)
Annotations may override this method to transform their properties (i.e. boolean
isResizable()
Check if the annotation is resizable, or if this is a non-resizable annotation. boolean
isLocked()
Check if the annotation is locked - i.e. -
-
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.
-
getAudioEncoding
@NonNull() AudioEncoding getAudioEncoding()
Encoding of the audio data.
- Returns:
Encoding used for audio data samples.
-
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.
-
getIconName
@SoundAnnotation.IconName()@NonNull() String getIconName()
Returns the name of the icon that should be displayed for this annotation.
- Returns:
Icon name, {@value ICON_NAME_SPEAKER} by default.
-
setIconName
void setIconName(@SoundAnnotation.IconName() String iconName)
Sets the name of the icon that should be displayed for this annotation.
- Parameters:
iconName
- Icon name to be set.
-
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) orfalse
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 orfalse
if it can be freely modified.
-
-
-
-