本文整理匯總了Java中android.media.AudioTrack.getState方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioTrack.getState方法的具體用法?Java AudioTrack.getState怎麽用?Java AudioTrack.getState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.AudioTrack
的用法示例。
在下文中一共展示了AudioTrack.getState方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startPlayer
import android.media.AudioTrack; //導入方法依賴的package包/類
public boolean startPlayer(int streamType, int sampleRateInHz, int channelConfig, int audioFormat) {
if (mIsPlayStarted) {
Log.e(TAG, "Player already started !");
return false;
}
mMinBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz,channelConfig,audioFormat);
if (mMinBufferSize == AudioTrack.ERROR_BAD_VALUE) {
Log.e(TAG, "Invalid parameter !");
return false;
}
Log.d(TAG , "getMinBufferSize = "+mMinBufferSize+" bytes !");
mAudioTrack = new AudioTrack(streamType,sampleRateInHz,channelConfig,audioFormat,mMinBufferSize,DEFAULT_PLAY_MODE);
if (mAudioTrack.getState() == AudioTrack.STATE_UNINITIALIZED) {
Log.e(TAG, "AudioTrack initialize fail !");
return false;
}
mIsPlayStarted = true;
Log.d(TAG, "Start audio player success !");
return true;
}
示例2: createAudioTrack
import android.media.AudioTrack; //導入方法依賴的package包/類
private void createAudioTrack() throws InitializationException {
// The AudioTrack configurations parameters used here, are guaranteed to
// be supported on all devices.
// AudioFormat.CHANNEL_OUT_MONO should be used in place of deprecated
// AudioFormat.CHANNEL_CONFIGURATION_MONO, but it is not available for
// API level 3.
// Output buffer for playing should be as short as possible, so
// AudioBufferPlayed events are not invoked long before audio buffer is
// actually played. Also, when AudioTrack is stopped, it is filled with
// silence of length audioTrackBufferSizeInBytes. If the silence is too
// long, it causes a delay before the next recorded data starts playing.
audioTrackBufferSizeInBytes = AudioTrack.getMinBufferSize(
SpeechTrainerConfig.SAMPLE_RATE_HZ,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if (audioTrackBufferSizeInBytes <= 0) {
throw new InitializationException("Failed to initialize playback.");
}
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
SpeechTrainerConfig.SAMPLE_RATE_HZ,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
audioTrackBufferSizeInBytes,
AudioTrack.MODE_STREAM);
if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
audioTrack = null;
throw new InitializationException("Failed to initialize playback.");
}
}