Java Code Examples for android.media.AudioTrack#PLAYSTATE_STOPPED

The following examples show how to use android.media.AudioTrack#PLAYSTATE_STOPPED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WakeupEngineBase.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
 * 打断(停止)唤醒,调用该方法后马上停止录音,但不保证完全打断唤醒,完全打断可能会有延迟
 */
public void stopListening(){
	Log.i(TAG, "stopListening");
	if(isListening())
	try{
		stopRecord();
		if(at.getPlayState()!= AudioTrack.PLAYSTATE_STOPPED){
			stopInterrupt.set(true);
		}
	}catch(Exception e){
		e.printStackTrace();
	}
}
 
Example 2
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void shutdown() {

    if (audioTrack != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        switch (audioTrack.getPlayState()) {
            case AudioTrack.PLAYSTATE_PLAYING:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_PLAYING");
                }
                audioTrack.stop(true);
                audioTrack.flush();
                audioTrack.release();
            case AudioTrack.PLAYSTATE_PAUSED:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_PAUSED");
                }
                audioTrack.stop(true);
                audioTrack.flush();
                audioTrack.release();
            case AudioTrack.PLAYSTATE_STOPPED:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_STOPPED");
                }
                audioTrack.flush();
                audioTrack.release();
                break;
        }
    }

    super.shutdown();
}
 
Example 3
Source File: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int stop() {

    if (audioTrack != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        switch (audioTrack.getPlayState()) {
            case AudioTrack.PLAYSTATE_PLAYING:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_PLAYING");
                }
                audioTrack.stop(true);
                return SUCCESS;
            case AudioTrack.PLAYSTATE_PAUSED:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_PAUSED");
                }
                audioTrack.stop(true);
                return SUCCESS;
            case AudioTrack.PLAYSTATE_STOPPED:
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "stop: PLAYSTATE_STOPPED");
                }
                break;
        }
    }

    try {
        return super.stop();
    } catch (final NullPointerException e) {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "stop: NullPointerException");
            e.printStackTrace();
        }
    }

    return ERROR;
}