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

Commit da823ac3 authored by Mike McCreavy's avatar Mike McCreavy Committed by Android (Google) Code Review
Browse files

Merge "Do not play audio if audio service is not ready"

parents 28dec20c f12277be
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#define CHATTY ALOGD
#define LOG_TAG "audioplay"

#include <binder/IServiceManager.h>

#include "audioplay.h"

#include <string.h>
@@ -316,8 +318,13 @@ public:
        : Thread(false),
          mExampleAudioData(exampleAudioData),
          mExampleAudioLength(exampleAudioLength) {}

private:
    virtual bool threadLoop() {
        if (defaultServiceManager()->checkService(String16("audio")) == nullptr) {
            ALOGW("Audio service is not ready yet, ignore creating playback engine");
            return false;
        }
        audioplay::create(mExampleAudioData, mExampleAudioLength);
        // Exit immediately
        return false;
@@ -406,14 +413,14 @@ bool create(const uint8_t* exampleClipBuf, int exampleClipBufSize) {
}

bool playClip(const uint8_t* buf, int size) {
    // Parse the WAV header
    const ChunkFormat* chunkFormat;
    if (!parseClipBuf(buf, size, &chunkFormat, &nextBuffer, &nextSize)) {
    if (!hasPlayer()) {
        ALOGE("cannot play clip %p without a player", buf);
        return false;
    }

    if (!hasPlayer()) {
        ALOGD("cannot play clip %p without a player", buf);
    // Parse the WAV header
    const ChunkFormat* chunkFormat;
    if (!parseClipBuf(buf, size, &chunkFormat, &nextBuffer, &nextSize)) {
        return false;
    }

@@ -438,11 +445,9 @@ bool playClip(const uint8_t* buf, int size) {
void setPlaying(bool isPlaying) {
    if (!hasPlayer()) return;

    SLresult result;

    if (nullptr != bqPlayerPlay) {
        // set the player's state
        result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay,
        (*bqPlayerPlay)->SetPlayState(bqPlayerPlay,
            isPlaying ? SL_PLAYSTATE_PLAYING : SL_PLAYSTATE_STOPPED);
    }