Skip to main content

AudioPlayer

Struct AudioPlayer 

Source
pub struct AudioPlayer { /* private fields */ }
Expand description

Rust wrapper for Android audio player

Implementations§

Source§

impl AudioPlayer

Source

pub fn new( env: JNIEnv<'_>, context: &GlobalRef, sample_rate: SampleRate, channel_config: ChannelOutConfig, audio_format: AudioEncoding, mode: PlayerMode, ) -> Result<Self, PlayerError>

Create a new AudioPlayer instance

§Arguments
  • env - JNI environment
  • context - GlobalRef to context object (used to get the correct ClassLoader)
  • sample_rate - Sample rate (e.g., SampleRate::Rate16000)
  • channel_config - Channel configuration (ChannelOutConfig::Mono or ChannelOutConfig::Stereo)
  • audio_format - Audio encoding format (AudioEncoding::Pcm8bit, AudioEncoding::Pcm16bit, or AudioEncoding::PcmFloat)
  • mode - Playback mode (PlayerMode::Static or PlayerMode::Stream)
§Returns

Returns initialized AudioPlayer instance

§Examples

See the README.md for complete usage examples.

Source

pub fn play(&self) -> Result<(), PlayerError>

Start playback

Source

pub fn stop(&self) -> Result<(), PlayerError>

Stop playback

Source

pub fn pause(&self) -> Result<(), PlayerError>

Pause playback

Source

pub fn flush(&self) -> Result<(), PlayerError>

Flush buffer

Source

pub fn release(&self) -> Result<(), PlayerError>

Release resources

Source

pub async fn write(&self, audio_data: &[u8]) -> Result<(), PlayerError>

Write audio data asynchronously

§Arguments
  • audio_data - Audio data (raw PCM data)
§Returns
  • Result<(), PlayerError> - Returns () on success, error on failure
§Examples

See the README.md for complete usage examples.

Source

pub fn get_sample_rate(&self) -> i32

Get sample rate

Source

pub fn get_channel_count(&self) -> i32

Get channel count

Source

pub fn get_audio_format(&self) -> i32

Get audio format

Source

pub fn get_mode(&self) -> i32

Get playback mode

Source

pub fn get_buffer_size(&self) -> Result<i32, PlayerError>

Get buffer size

Trait Implementations§

Source§

impl Drop for AudioPlayer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for AudioPlayer

Source§

impl Sync for AudioPlayer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more