public class

AudioExtractor

extends Object
java.lang.Object
   ↳ com.pspdfkit.annotations.sound.AudioExtractor

Class Overview

Extracts audio from media files into EmbeddedAudioSource that is usable for creating SoundAnnotation.

Supported formats depend on the device (see https://developer.android.com/guide/topics/media/media-formats).

Summary

Public Constructors
AudioExtractor(Context context, Uri contentUri)
Creates audio extractor for media file at contentUri.
Public Methods
EmbeddedAudioSource extractAudioTrack()
Extracts selected audio track as an EmbeddedAudioSource that can be set on SoundAnnotation.
Single<EmbeddedAudioSource> extractAudioTrackAsync()
Extracts selected audio track as an EmbeddedAudioSource that can be set on SoundAnnotation, asynchronously.
int getAudioTracksCount()
Number of audio tracks in the media file.
long getSelectedTrackDuration()
Returns selected track duration in milliseconds.
synchronized void selectAudioTrack(int audioTrackIndex)
Selects audio track for decoding.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public AudioExtractor (Context context, Uri contentUri)

Creates audio extractor for media file at contentUri.

Parameters
context Context to use.
contentUri A media content URI with supported scheme (content:// or file://).
Throws
IOException If the media can't be opened.

Public Methods

public EmbeddedAudioSource extractAudioTrack ()

Extracts selected audio track as an EmbeddedAudioSource that can be set on SoundAnnotation. Defaults to decoding first audio track if track has not been selected via selectAudioTrack(int).

Returns
  • Decoded audio source.
Throws
IOException When audio could not be decoded.

public Single<EmbeddedAudioSource> extractAudioTrackAsync ()

Extracts selected audio track as an EmbeddedAudioSource that can be set on SoundAnnotation, asynchronously. Defaults to decoding first audio track if track has not been selected via selectAudioTrack(int).

Returns
  • Single emitting audio source with extracted track data or error if track could not be extracted.

public int getAudioTracksCount ()

Number of audio tracks in the media file.

Returns
  • Number of audio tracks in the media file.

public long getSelectedTrackDuration ()

Returns selected track duration in milliseconds.

Returns
  • Duration of the selected track in milliseconds or 0 if the duration could not be retrieved or no track has been selected via selectAudioTrack(int).

public synchronized void selectAudioTrack (int audioTrackIndex)

Selects audio track for decoding.

Parameters
audioTrackIndex Audio track index, must be >= 0 and smaller than getAudioTracksCount().
Throws
IOException If the decoder for audio track could not be created.