AudioTrack: SetLoopPoint issue

All your problems with Audio, Video and Images.

AudioTrack: SetLoopPoint issue

Postby jwchg » Mon Nov 22, 2010 6:08 am

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 infinite 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.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  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,
  14.          AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STATIC);
  15.          while(bytesWritten < fileSize){
  16.              try {
  17.                  bytesRead = audioStream.read(buffer, 0, bufferSize);
  18.              } catch (IOException e) {
  19.                  e.printStackTrace();
  20.              }
  21.              bytesWritten += next_track.write(buffer, 0, bytesRead);
  22.          }
  23.          try {
  24.              audioStream.close();
  25.              audioStream = null;
  26.          } catch (IOException e) {
  27.              // TODO Auto-generated catch block
  28.              e.printStackTrace();
  29.          }
  30.          load_complete = true;
  31.      }
  32.   }).start();
  33. }
  34.  
  35. public void Play(){
  36.   track.reloadStaticData();
  37.   if(startInFrames2 != 0 && endInFrames2 != 0){
  38.      track.setLoopPoints(startInFrames2, endInFrames2, 2);
  39.   }
  40.   track.setStereoVolume(bgm_now_vol, bgm_now_vol);
  41.   track.play();
  42. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
Please help. Thanks in advance.
jwchg
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 22, 2010 4:59 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests