1. Download our Official Android App: Forums for Android!

Apps AudioTrack: SetLoopPoint issue

Discussion in 'Android Development' started by jwchg, Nov 22, 2010.

  1. jwchg

    jwchg Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Nov 21, 2010

    Nov 21, 2010
    2
    0
    5
    Hi All,
    I am developing an audio library for my game application but i met a problem when i tried to set loop point using AudioTrack. The audio track worked fine when i set the loop to infinity loop. But when i set the loop to a finite number, for example 2, the audio track looped for twice then at the end of the loop frame, it restarted from the beginning of the track and stopped at the end of the track.
    Is there any way to stop the loop so that the track will not be restarted again?
    Here is my Load and Play method.
    Code (Text):
    1. public void Load(){  
    2.    new Thread(new Runnable(){      
    3.        @Override      
    4.        public void run() {          
    5.            File audioFile = new File(next_bgm);          
    6.            fileSize = audioFile.length();          
    7.            bufferSize = (int)fileSize;          
    8.            try {              
    9.                audioStream = new FileInputStream(audioFile);          
    10.            } catch (FileNotFoundException e) {            
    11.                e.printStackTrace();          
    12.            }          
    13.            next_track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_STEREO,           AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STATIC);          
    14.            while(bytesWritten < fileSize){              
    15.                try {                  
    16.                    bytesRead = audioStream.read(buffer, 0, bufferSize);              
    17.                } catch (IOException e) {              
    18.                    e.printStackTrace();              
    19.                }              
    20.                bytesWritten += next_track.write(buffer, 0, bytesRead);        
    21.            }          
    22.            try {            
    23.                audioStream.close();              
    24.                audioStream = null;          
    25.            } catch (IOException e) {              
    26.                // TODO Auto-generated catch block          
    27.                e.printStackTrace();          
    28.            }          
    29.            load_complete = true;      
    30.        }
    31.    }).start();
    32. }  
    33.  
    34. public void Play(){  
    35.    track.reloadStaticData();  
    36.    if(startInFrames2 != 0 && endInFrames2 != 0){      
    37.        track.setLoopPoints(startInFrames2, endInFrames2, 2);  
    38.    }  
    39.    track.setStereoVolume(bgm_now_vol, bgm_now_vol);  
    40.    track.play();
    41. }
    Please help. Thanks in advance.
     

    Advertisement

Share This Page

Loading...