Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Converting wav's to mp3's  (Read 2852 times)
0 Members and 1 Guest are viewing this topic.
Offline eedok

Junior Newbie





« Posted 2009-09-30 00:16:41 »

I'm trying to make a tool to convert wav's to mp3's then send out a notification when it's done. (The wav's will always be 44100Hz 16-bit Stereo files)

My first attempt was to link to JMF then attempt to do this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   public void wavToMP3(String waveFileName, String mp3FileName) throws Exception
   {
      File file = new File(waveFileName);
      AudioInputStream in = AudioSystem.getAudioInputStream(file);
      AudioInputStream out;
      AudioFormat.Encoding encodedFormat = new AudioFormat.Encoding(javax.media.format.AudioFormat.MPEGLAYER3);
      out = AudioSystem.getAudioInputStream(encodedFormat, in);
      File outfile = new File(mp3FileName);
      AudioSystem.write(out, new AudioFileFormat.Type("MP3","mp3"), outfile);
   }


but that results in this error:

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: mpeglayer3 from PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

I can't seem to find what I need to change to fix this, any suggestions?
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #1 - Posted 2009-09-30 03:29:22 »

The JDK can't read MP3s. You can use the JavaZoom project. It isn't written very well, but works for most MP3s.

Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #2 - Posted 2009-09-30 08:25:35 »

And just on the off-chance - if you can get away with using Ogg Vorbis format instead of MP3, you can use the JOrbis library.

Cas Smiley

Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #3 - Posted 2009-09-30 11:56:13 »

Indeed. OGG, FLAC, and APE have decent Java decoding libs.

Offline eedok

Junior Newbie





« Reply #4 - Posted 2009-09-30 21:51:29 »

the final format needs to be mp3 to be playable in flash(this is on the server) and as far as I know it doesn't support ogg, flac or ape

it also seems javazoom's domain is down
Offline eedok

Junior Newbie





« Reply #5 - Posted 2009-10-02 18:31:10 »

I found a link to JLayer and it only seems to be able to go from mp3->wav but has no way of going back again, is there a library to do this that doesn't require an EasyJNI license?
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #6 - Posted 2009-10-03 04:51:46 »

Don't think so. Stupid, eh?

Offline eedok

Junior Newbie





« Reply #7 - Posted 2009-10-06 23:55:05 »

I guess this will have to do:
1  
2  
3  
4  
5  
   public void wavToMP3(String waveFileName, String mp3FileName) throws Exception
   {
      Runtime runtime = Runtime.getRuntime();
      Process proc = runtime.exec(LAME_PATH+" "+waveFileName+" "+mp3FileName);
   }
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (142 views)
2013-05-17 21:29:12

alaslipknot (150 views)
2013-05-16 21:24:48

gouessej (181 views)
2013-05-16 00:53:38

gouessej (174 views)
2013-05-16 00:17:58

theagentd (184 views)
2013-05-15 15:01:13

theagentd (169 views)
2013-05-15 15:00:54

StreetDoggy (213 views)
2013-05-14 15:56:26

kutucuk (237 views)
2013-05-12 17:10:36

kutucuk (236 views)
2013-05-12 15:36:09

UnluckyDevil (241 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.083 seconds with 20 queries.