Java Code Examples for android.media.AudioTrack#PLAYSTATE_PAUSED

The following examples show how to use android.media.AudioTrack#PLAYSTATE_PAUSED . 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: SaiyTextToSpeech.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean isSpeaking() {

    if (audioTrack != null && audioTrack.getState() == AudioTrack.STATE_INITIALIZED) {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "isSpeaking: audioTrack STATE_INITIALIZED");
        }

        if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING
                || audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PAUSED) {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "isSpeaking: audioTrack PLAYSTATE_PLAYING/PLAYSTATE_PAUSED");
            }
            return true;
        } else {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "isSpeaking: audioTrack not playing");
            }
        }
    }

    final boolean speakingSuper = super.isSpeaking();

    if (DEBUG) {
        MyLog.i(CLS_NAME, "isSpeaking: speakingSuper " + speakingSuper);
    }

    return speakingSuper;
}
 
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;
}
 
Example 4
Source File: AudioTrackPositionTracker.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * If passthrough workarounds are enabled, pausing is implemented by forcing the AudioTrack to
 * underrun. In this case, still behave as if we have pending data, otherwise writing won't
 * resume.
 */
private boolean forceHasPendingData() {
  return needsPassthroughWorkarounds
      && Assertions.checkNotNull(audioTrack).getPlayState() == AudioTrack.PLAYSTATE_PAUSED
      && getPlaybackHeadPosition() == 0;
}
 
Example 5
Source File: SamplePlayer.java    From YTPlayer with GNU General Public License v3.0 4 votes vote down vote up
public boolean isPaused() {
    return mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PAUSED;
}
 
Example 6
Source File: AudioTrackPositionTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If passthrough workarounds are enabled, pausing is implemented by forcing the AudioTrack to
 * underrun. In this case, still behave as if we have pending data, otherwise writing won't
 * resume.
 */
private boolean forceHasPendingData() {
  return needsPassthroughWorkarounds
      && Assertions.checkNotNull(audioTrack).getPlayState() == AudioTrack.PLAYSTATE_PAUSED
      && getPlaybackHeadPosition() == 0;
}
 
Example 7
Source File: AudioTrackPositionTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If passthrough workarounds are enabled, pausing is implemented by forcing the AudioTrack to
 * underrun. In this case, still behave as if we have pending data, otherwise writing won't
 * resume.
 */
private boolean forceHasPendingData() {
  return needsPassthroughWorkarounds
      && Assertions.checkNotNull(audioTrack).getPlayState() == AudioTrack.PLAYSTATE_PAUSED
      && getPlaybackHeadPosition() == 0;
}
 
Example 8
Source File: AudioTrackPositionTracker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If passthrough workarounds are enabled, pausing is implemented by forcing the AudioTrack to
 * underrun. In this case, still behave as if we have pending data, otherwise writing won't
 * resume.
 */
private boolean forceHasPendingData() {
  return needsPassthroughWorkarounds
      && Assertions.checkNotNull(audioTrack).getPlayState() == AudioTrack.PLAYSTATE_PAUSED
      && getPlaybackHeadPosition() == 0;
}
 
Example 9
Source File: AudioTrackPositionTracker.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * If passthrough workarounds are enabled, pausing is implemented by forcing the AudioTrack to
 * underrun. In this case, still behave as if we have pending data, otherwise writing won't
 * resume.
 */
private boolean forceHasPendingData() {
  return needsPassthroughWorkarounds
      && Assertions.checkNotNull(audioTrack).getPlayState() == AudioTrack.PLAYSTATE_PAUSED
      && getPlaybackHeadPosition() == 0;
}