Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 4240 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 Kernel


Medals: 145
Projects: 4
Exp: 14 years


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.

Online princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


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!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


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 Kernel


Medals: 145
Projects: 4
Exp: 14 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!