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

Commit ea7cb6a0 authored by MingWei's avatar MingWei
Browse files

Take offset into account while writing bytes into audio track.

BUG: 158281489
Test: Trivial change.
Change-Id: Ib3e3462b3193db90b1374d3aad87266e37af228f
parent 37d8f86b
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -194,17 +194,22 @@ class BlockingAudioTrack {
            audioTrack.play();
        }

        int count = 0;
        while (count < bytes.length) {
            // Note that we don't take bufferCopy.mOffset into account because
            // it is guaranteed to be 0.
            int written = audioTrack.write(bytes, count, bytes.length);
        int offset = 0;
        while (offset < bytes.length) {
            // Although it requests to write the entire bytes at once, it might fail when the track
            // got stopped or the thread is interrupted. In that case, it needs to carry on from
            // last offset.
            int sizeToWrite = bytes.length - offset;
            int written = audioTrack.write(bytes, offset, sizeToWrite);
            if (written <= 0) {
                if (written < 0) {
                    Log.e(TAG, "An error occurred while writing to audio track: " + written);
                }
                break;
            }
            count += written;
            offset += written;
        }
        return count;
        return offset;
    }

    private AudioTrack createStreamingAudioTrack() {