Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c19137b authored by Andy Hung's avatar Andy Hung
Browse files

AudioTrack: Add getAudioAttributes public method

Bug: 116735841
Test: AudioTrackTest#testBuilderAttributesStream
Change-Id: I09c69ed42a7a76d3d85694dd120a54f5567fb164
parent 909810d4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23250,6 +23250,7 @@ package android.media {
    method public android.media.VolumeShaper createVolumeShaper(android.media.VolumeShaper.Configuration);
    method protected void finalize();
    method public void flush();
    method public android.media.AudioAttributes getAudioAttributes();
    method public int getAudioFormat();
    method public int getAudioSessionId();
    method public int getBufferCapacityInFrames();
+23 −0
Original line number Diff line number Diff line
@@ -370,6 +370,10 @@ public class AudioTrack extends PlayerBase
     * @see AudioFormat#ENCODING_PCM_FLOAT
     */
    private int mAudioFormat;   // initialized by all constructors via audioParamCheck()
    /**
     * The AudioAttributes used in configuration.
     */
    private AudioAttributes mConfiguredAudioAttributes;
    /**
     * Audio session ID
     */
@@ -570,6 +574,8 @@ public class AudioTrack extends PlayerBase
        super(attributes, AudioPlaybackConfiguration.PLAYER_TYPE_JAM_AUDIOTRACK);
        // mState already == STATE_UNINITIALIZED

        mConfiguredAudioAttributes = attributes; // object copy not needed, immutable.

        if (format == null) {
            throw new IllegalArgumentException("Illegal null AudioFormat");
        }
@@ -1300,6 +1306,23 @@ public class AudioTrack extends PlayerBase
        return native_get_playback_params();
    }

    /**
     * Returns the {@link AudioAttributes} used in configuration.
     * If a {@code streamType} is used instead of an {@code AudioAttributes}
     * to configure the AudioTrack
     * (the use of {@code streamType} for configuration is deprecated),
     * then the {@code AudioAttributes}
     * equivalent to the {@code streamType} is returned.
     * @return The {@code AudioAttributes} used to configure the AudioTrack.
     * @throws IllegalStateException If the track is not initialized.
     */
    public @NonNull AudioAttributes getAudioAttributes() {
        if (mState == STATE_UNINITIALIZED || mConfiguredAudioAttributes == null) {
            throw new IllegalStateException("track not initialized");
        }
        return mConfiguredAudioAttributes;
    }

    /**
     * Returns the configured audio data encoding. See {@link AudioFormat#ENCODING_PCM_8BIT},
     * {@link AudioFormat#ENCODING_PCM_16BIT}, and {@link AudioFormat#ENCODING_PCM_FLOAT}.