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.
Please help. Thanks in advance.
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:
public void Load(){
new Thread(new Runnable(){
@Override
public void run() {
File audioFile = new File(next_bgm);
fileSize = audioFile.length();
bufferSize = (int)fileSize;
try {
audioStream = new FileInputStream(audioFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
next_track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STATIC);
while(bytesWritten < fileSize){
try {
bytesRead = audioStream.read(buffer, 0, bufferSize);
} catch (IOException e) {
e.printStackTrace();
}
bytesWritten += next_track.write(buffer, 0, bytesRead);
}
try {
audioStream.close();
audioStream = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
load_complete = true;
}
}).start();
}
public void Play(){
track.reloadStaticData();
if(startInFrames2 != 0 && endInFrames2 != 0){
track.setLoopPoints(startInFrames2, endInFrames2, 2);
}
track.setStereoVolume(bgm_now_vol, bgm_now_vol);
track.play();
}