Code example for AudioTrack

Methods: flushgetPlayStatepauseplaystopwrite, setPositionNotificationPeriod

0
            m_Read = 0; 
            waiteinQueuesize = 0; 
            _stop(); 
            try 
            { 
                int state = m_AudioTrack.setPositionNotificationPeriod(mPeriodicInFrames); 
                Log.d("AudioPlay2", "setPositionNotificationPeriod  state:" + state); 
                // state = m_AudioTrack.setPlaybackHeadPosition(0); 
                // Log.d("AudioPlay2", "setPlaybackHeadPosition state:" + 
                // state); 
                if (m_AudioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) 
                { 
                    m_AudioTrack.play(); 
                } 
                m_Read = fIn.read(iBuffer); 
                if (m_Read == -1) 
                { 
                    fIn = null; 
                    m_AudioTrack.stop(); 
                    mAudioThreadHandler.removeCallbacks(run); 
                    mMainHandler.sendEmptyMessage(MSG_ONERR); 
                    return; 
                } 
                m_Write = m_AudioTrack.write(iBuffer, 0, m_Read); 
                waiteinQueuesize = m_Write; 
                mHasData = true; 
            } 
            catch (FileNotFoundException e) 
            { 
                e.printStackTrace(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            mAudioThreadHandler.removeCallbacks(run); 
            mAudioThreadHandler.postDelayed(run, iTimeToAppendAudio); 
        } 
 
        public void _stop() 
        { 
            mAudioThreadHandler.removeCallbacks(run); 
            mAudioThreadHandler.removeCallbacks(m_Stop); 
            if (m_AudioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) 
            { 
                m_AudioTrack.flush(); 
                m_AudioTrack.pause(); 
                m_AudioTrack.stop(); 
            } 
        } 
 
        @Override 
        public void run()