Beispiel #1
0
  public void convertWavToMP3(String filepathToConvert, String convertedFilePath) {
    Encoder wavToMp3Converter = new Encoder();
    EncodingAttributes att = new EncodingAttributes();
    AudioAttributes audioAtt = new AudioAttributes();
    String codecs[] = null;
    String formats[] = null;
    try {
      formats = wavToMp3Converter.getSupportedDecodingFormats();
    } catch (EncoderException e) {
      e.printStackTrace();
    }
    try {
      codecs = wavToMp3Converter.getAudioEncoders();
    } catch (EncoderException e) {
      e.printStackTrace();
    }
    int mp3CodecIndex = -1;
    /*for(int i=codecs.length; i>0; i--)
    {
        if(codecs[i].compareTo("") == 0)
        {
            mp3CodecIndex = i;
            break;
        }
    }*/
    audioAtt.setVolume(255);
    audioAtt.setSamplingRate(new Integer(this.getWavTagReader().sampleRate));
    audioAtt.setChannels(new Integer(wavTagReader.numOfChannels));
    audioAtt.setBitRate(
        new Integer(
            this.wavTagReader.sampleRate
                * this.wavTagReader.bitsPerSample
                * this.wavTagReader.numOfChannels));
    audioAtt.setCodec("libmp3lame");
    att.setAudioAttributes(audioAtt);
    att.setFormat("mp3");
    att.setOffset(new Float((float) 0));
    att.setVideoAttributes(null);
    // att.setDuration(new Float((float)100));
    try {
      wavToMp3Converter.encode(
          new File(filepathToConvert),
          new File(convertedFilePath),
          att,
          new EncoderProgressListener() {
            @Override
            public void sourceInfo(MultimediaInfo multimediaInfo) {}

            @Override
            public void progress(int i) {}

            @Override
            public void message(String s) {}
          });
    } catch (EncoderException e) {
      e.getMessage();

      e.getCause();
    }
  }
Beispiel #2
0
 /**
  * Converts WAV file to MP3
  *
  * @param filePath path on which MP3 file will be saved
  */
 public void convertWavToMP3(String filePath) {
   String codecs[];
   String formats[];
   Encoder encoder = new Encoder();
   EncodingAttributes att = new EncodingAttributes();
   try {
     codecs = encoder.getAudioEncoders();
     formats = encoder.getSupportedEncodingFormats();
     AudioAttributes audioAtt = new AudioAttributes();
     audioAtt.setBitRate(
         this.wavTagReader.getByteRate()
             * this.wavTagReader.getBitsPerSample()
             * this.wavTagReader.getNumOfChannels());
     audioAtt.setChannels(Integer.valueOf(this.wavTagReader.getNumOfChannels()));
     audioAtt.setSamplingRate(this.wavTagReader.getSampleRate());
     audioAtt.setVolume(255);
     audioAtt.setCodec(AudioAttributes.DIRECT_STREAM_COPY);
     att.setAudioAttributes(audioAtt);
     att.setFormat("mp3");
     encoder.encode(this.file, new File(filePath), att);
   } catch (EncoderException e) {
     e.printStackTrace();
   }
 }