當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioTrack.setNotificationMarkerPosition方法代碼示例

本文整理匯總了Java中android.media.AudioTrack.setNotificationMarkerPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioTrack.setNotificationMarkerPosition方法的具體用法?Java AudioTrack.setNotificationMarkerPosition怎麽用?Java AudioTrack.setNotificationMarkerPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.AudioTrack的用法示例。


在下文中一共展示了AudioTrack.setNotificationMarkerPosition方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: playSound

import android.media.AudioTrack; //導入方法依賴的package包/類
/**
 * This method plays the sound data in the specified buffer.
 *
 * @param buffer specifies the sound data buffer.
 */
public void playSound(short[] buffer)
{
    final String funcName = "playSound";

    if (debugEnabled)
    {
        dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.API);
        dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.API);
    }

    audioTrack = new AudioTrack(
            AudioManager.STREAM_MUSIC,
            sampleRate,
            AudioFormat.CHANNEL_OUT_MONO,
            AudioFormat.ENCODING_PCM_16BIT,
            buffer.length*2,    //buffer length in bytes
            AudioTrack.MODE_STATIC);
    audioTrack.write(buffer, 0, buffer.length);
    audioTrack.setNotificationMarkerPosition(buffer.length);
    audioTrack.setPlaybackPositionUpdateListener(this);
    audioTrack.play();
    playing = true;
}
 
開發者ID:trc492,項目名稱:Ftc2018RelicRecovery,代碼行數:29,代碼來源:FtcAndroidTone.java

示例2: generateTrack

import android.media.AudioTrack; //導入方法依賴的package包/類
public AudioTrack generateTrack(int sampleRate, short[] buf, int len) {
    int end = len;

    int c = 0;

    if (RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO)
        c = AudioFormat.CHANNEL_OUT_MONO;

    if (RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_STEREO)
        c = AudioFormat.CHANNEL_OUT_STEREO;

    // old phones bug.
    // http://stackoverflow.com/questions/27602492
    //
    // with MODE_STATIC setNotificationMarkerPosition not called
    AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
            c, RawSamples.AUDIO_FORMAT,
            len * (Short.SIZE / 8), AudioTrack.MODE_STREAM);
    track.write(buf, 0, len);
    if (track.setNotificationMarkerPosition(end) != AudioTrack.SUCCESS)
        throw new RuntimeException("unable to set marker");
    return track;
}
 
開發者ID:NandagopalR,項目名稱:Android-Audio-Recorder,代碼行數:24,代碼來源:Sound.java

示例3: generateTone

import android.media.AudioTrack; //導入方法依賴的package包/類
static private AudioTrack generateTone(double freqHz, int durationMs) {
	int count = (int) (44100.0 * 2.0 * (durationMs / 1000.0)) & ~1;
	short[] samples = new short[count];
	int size = count * (Short.SIZE / 8);
	Log.d(TAG, freqHz + "Hz for " + durationMs + "ms = " + count + " samples at 44.1Khz 2ch = " + size + " bytes");
	for (int i = 0; i < count; i += 2) {
		short sample = (short) (Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF * .75);
		samples[i + 0] = sample;
		samples[i + 1] = sample;
	}
	AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,
			AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
			size, AudioTrack.MODE_STATIC);
	track.setNotificationMarkerPosition(count / 2);
	track.write(samples, 0, count);
	return track;
}
 
開發者ID:tharvey,項目名稱:BlocklyBot,代碼行數:18,代碼來源:Tone.java


注:本文中的android.media.AudioTrack.setNotificationMarkerPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。