Share via


AudioTrack.SetPlaybackRate(Int32) Method

Definition

Sets the playback sample rate for this track.

[Android.Runtime.Register("setPlaybackRate", "(I)I", "GetSetPlaybackRate_IHandler")]
public virtual int SetPlaybackRate (int sampleRateInHz);
[<Android.Runtime.Register("setPlaybackRate", "(I)I", "GetSetPlaybackRate_IHandler")>]
abstract member SetPlaybackRate : int -> int
override this.SetPlaybackRate : int -> int

Parameters

sampleRateInHz
Int32

the sample rate expressed in Hz

Returns

error code or success, see #SUCCESS, #ERROR_BAD_VALUE, #ERROR_INVALID_OPERATION

Attributes

Remarks

Sets the playback sample rate for this track. This sets the sampling rate at which the audio data will be consumed and played back (as set by the sampleRateInHz parameter in the #AudioTrack(int, int, int, int, int, int) constructor), not the original sampling rate of the content. For example, setting it to half the sample rate of the content will cause the playback to last twice as long, but will also result in a pitch shift down by one octave. The valid sample rate range is from 1 Hz to twice the value returned by #getNativeOutputSampleRate(int). Use #setPlaybackParams(PlaybackParams) for speed control.

This method may also be used to repurpose an existing AudioTrack for playback of content of differing sample rate, but with identical encoding and channel mask.

Java documentation for android.media.AudioTrack.setPlaybackRate(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to