下面列出了android.media.AudioTrack#PLAYSTATE_PAUSED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
@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();
}
@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;
}
/**
* 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;
}
public boolean isPaused() {
return mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PAUSED;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}