title: which jar file can be used to play an audio file in android
body: <p>When I was searching through google I found a java program created in netbeans to calculate the bpm of a song. It was working with a lot of JAR files.</p>
  
  <p>I used the same code for my android app and it showed lot of errors due to the missing of only one JAR file. I added the JLayer1.0.1 jar file and all the errors were cleared.</p>
  
  <p>Now the app is working good but the bpm calculation is creating some new problems. It gives the bpm of a song which is less than 1 min but the others songs are not always been in process for a hour. And the songs are not been played in the background. </p>
  
  <p>When I checked with the Java program there it is calculating the bpm of all songs and the songs are been played and I can hear it. </p>
  
  <p>What is the problem I am facing here? Is this all because of the JAR file, am I supposed to use any other JAR files? Please help me friends....</p>
  
  <p>I am adding a part of my code</p>
  
  <pre><code>Player player = new Player(new FileInputStream("//sdcard//taxi.mp3"), output);
  
      public class BPM2SampleProcessor implements SampleProcessor {
  
          private Queue&lt;Long&gt; energyBuffer = new LinkedList&lt;Long&gt;();
  
          private int bufferLength = 43;
  
          private long sampleSize = 1024;
          private long frequency = 44100;
          private long samples = 0;
          private long beats = 0;
          private static int beatThreshold = 3;
          private int beatTriggers = 0;
  
          private List&lt;Integer&gt; bpmList = new LinkedList&lt;Integer&gt;();
  
          public void process(long[] sample) {
              energyBuffer.offer(sample[0]);
              samples++;
              if(energyBuffer.size() &gt; bufferLength) {
                  energyBuffer.poll();
                  double averageEnergy = 0;
                  for(long l : energyBuffer)
                      averageEnergy += l;
                  averageEnergy /= bufferLength;
  
                  double C = 1.3; //a * variance + b;
                  boolean beat = sample[0] &gt; C * averageEnergy;
                  if(beat)
                  {
                      if(++beatTriggers == beatThreshold)
                          beats ++;
                  }
                  else
                  {
                      beatTriggers = 0;
                  }
  
                  if(samples &gt; frequency * 5 / sampleSize) {
                      bpmList.add(getInstantBPM());
                      beats = 0;
                      samples = 0;
                  }
              }
          }
  
          public void init(int freq, int channels) {
              frequency = freq;
          }
  
  
          public int getInstantBPM() {
              return (int)((beats * frequency * 60) / (samples * sampleSize));
          }
  
          public int getBPM() {
              Collections.sort(bpmList);
              return bpmList.get(bpmList.size() / 2);
          }
  
          public long getSampleSize() {
              return sampleSize;
          }
  
          public void setSampleSize(long sampleSize) {
              this.sampleSize = sampleSize;
          }
  
  }
  
  public class EnergyOutputAudioDevice extends BaseOutputAudioDevice {
      private int averageLength = 1024; // number of samples over which the average is calculated
      private Queue&lt;Short&gt; instantBuffer = new LinkedList&lt;Short&gt;();
  
      public EnergyOutputAudioDevice(SampleProcessor processor) {
          super(processor);
      }
  
      @Override
      protected void outputImpl(short[] samples, int offs, int len) throws JavaLayerException {
          for(int i=0; i&lt;len; i++)
              instantBuffer.offer(samples[i]);
  
          while(instantBuffer.size()&gt;averageLength*channels)
          {
              long energy = 0;
              for(int i=0; i&lt;averageLength*channels; i++)
                  energy += Math.pow(instantBuffer.poll(), 2);
  
              if(processor != null)
                  processor.process(new long[] { energy });
          }
      }
  
      public int getAverageLength() {
          return averageLength;
      }
  
      public void setAverageLength(int averageLength) {
          this.averageLength = averageLength;
      }
  }
  </code></pre>