AudioTrack stop - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AudioTrack stop method.

This code example shows how to use the following methods:release, stop
thread = null;
		 
 
		if(oTrack!=null){
			oTrack.stop();
			oTrack.release();
			oTrack = null;
		} 
		if(iTrack!=null){
			iTrack.release();
			iTrack = null;
		} 
		 
	} 
 
	@Override 
	protected void appPause() { 
		if(broadcastReceiver != null){
			try{ 
8
CodeRank
This code example shows how to use the following methods:release, stop
 
    public int deinitAudio() 
    { 
        if( mAudio != null )
        { 
            mAudio.stop();
            mAudio.release();
            mAudio = null;
        } 
        mAudioBuffer = null;
        return 1; 
    } 
 
    public int initAudioThread() 
    { 
        // Make audio thread priority higher so audio thread won't get underrun 
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        return 1; 
    } 
 
7
CodeRank
This code example shows how to use the following methods:play, stop, write
	 
	/** 
	 * This method merely plays whatever is currently on the sound buffer. 
	 */ 
	private void playSoundBuffer(){ 
		audioTrack.play();
		audioTrack.write(soundBuffer, 0, minBufferSize);
		audioTrack.stop();
	} 
	 
	/** 
	 * This method will be run by the client to execute some meaningless debugging sounds 
	 * to check the voltage levels produced etc. 
	 */ 
	public void debug(){ 
		if(minBufferSize < SOUND_SIZE){
			Log.e(TAG, "Buffer size too small");
		} 
		short currentLeftLevel = PCM_BIT_LOW;
		short currentRightLevel = PCM_BIT_HIGH;
6
CodeRank
This code example shows how to use the following methods:flush, stop
			track.play();
	} 
 
	static void audioStop() { 
		if (track != null) {
			track.stop();
			track.flush();
		} 
	} 
 
	static void audioPause() { 
		if (track != null)
			track.pause();
	} 
 
	static void audioPlay(byte[] data, int size) {
		if (track != null)
			track.write(data, 0, size);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:release, stop
		track.play();
		latency = minSize / (isMono?1:2);
	} 
 
	@Override public void dispose () { 
		track.stop();
		track.release();
	} 
 
	@Override public boolean isMono () { 
		return isMono;
	} 
 
	@Override public void writeSamples (short[] samples, int offset, int numSamples) {
		int writtenSamples = track.write(samples, offset, numSamples);
		while (writtenSamples != numSamples)
			writtenSamples += track.write(samples, offset + writtenSamples, numSamples - writtenSamples);
	} 
 
	@Override public void writeSamples (float[] samples, int offset, int numSamples) {
7
CodeRank
This code example shows how to use the following methods:release, stop
	 
	public int deinitAudio() 
	{ 
		if( mAudio != null )
		{ 
			mAudio.stop();
			mAudio.release();
			mAudio = null;
		} 
		mAudioBuffer = null;
		return 1; 
	} 
	 
	public int initAudioThread() 
	{ 
		// Make audio thread priority higher so audio thread won't get underrun 
		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		return 1; 
	} 
	 
6
CodeRank
This code example shows how to use the following methods:release, stop
        }).start();
    } 
 
    private void stopPlayer(boolean reinit) {
        if(audiotrack != null) {
            try { audiotrack.stop(); } catch(Exception e) { e.printStackTrace(); }
            audiotrack.release();
            audiotrack = null;
            audio = null;
        } 
        if(reinit) {
            initializeAudioTrack(); 
        } 
    } 
 
    private void pausePlayer() { 
        if(audiotrack != null) {
            audiotrack.pause();
        } 
    } 
7
CodeRank
This code example shows how to use the following methods:getPlayState, getState, play, release, setPlaybackHeadPosition
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         
        //-------- initialization -------------- 
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
                2*minBuffSize, TEST_MODE);
        byte data[] = new byte[minBuffSize];
        // make up a frame index that's beyond what has been written: go from buffer size to frame 
        //   count (given the audio track properties), and add 77. 
        int frameIndexTooFar = (2*minBuffSize/2) + 77;
        //--------    test        -------------- 
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        track.play();
        track.stop();
        assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED);
        assertTrue(TEST_NAME, track.setPlaybackHeadPosition(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE);
        //-------- tear down      -------------- 

6
CodeRank
This code example shows how to use the following methods:release, stop
    	if ( pipe != null ) {
    		Log.i( TAG , "[ shutdown() ] closing pipe");
    		pipe.close();
    	} 
    	if ( audioTrack != null ) {
    		audioTrack.stop();
    		audioTrack.release();
    	} 
         
    } 
 
     
} 
6
CodeRank
This code example shows how to use the following methods:getPlayState, play, reloadStaticData, stop, write
            byte[] b = new byte[length + SPACER];
            System.arraycopy(wav, 44, b, 0, length);
            Arrays.fill(b, length, length + SPACER, (byte)0);
             
            // バッファを一旦読み込む必要がある 
            track.reloadStaticData();
            // バッファに書き込む 
            // 無音区間を含めて書きこむ 
            //track.setNotificationMarkerPosition(length / 2); 
            track.write(b, 0, length + SPACER);
            // 再生 
            track.play();
            // setNotificationMarkerPositionによるコールバックが効かないので、 
            // 再生直後にステータスを書き換える 
            stop(); 
        } 
    } 
     
    /** 
     * 音声再生を停止する 

6
CodeRank

Related AudioTrack stop Questions & Answers:

stop Method Overview
Stops playing the audio data.
See Code Examples for other Android AudioTrack Methods: