Sunday, February 9, 2014

Java Play MP3 File

1. Download Java Media Framework (JMF) from : http://www.oracle.com/technetwork/java/javase/download-142937.html
2. Download MP3 Plugin from : http://www.oracle.com/technetwork/java/javase/download-137625.html or http://pscode.org/lib/mp3plugin.jar
3. Code for playing the mp3 file is like :


import javax.media.Manager;
import javax.media.Player;
import javax.media.Format;
import javax.media.MediaLocator;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;

...
        Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
        Format input2 = new AudioFormat(AudioFormat.MPEG);
        Format output = new AudioFormat(AudioFormat.LINEAR);

        Format[] formatIn = new Format[2];
        formatIn[0] = input1;
        formatIn[1] = input2;

        Format[] out = new Format[1];
        out[0] = output;

        File mp3file = new File("a.mp3");

        PlugInManager.addPlugIn(
            "com.sun.media.codec.audio.mp3.JavaDecoder",
            formatIn,
            out,
            PlugInManager.CODEC
        );
        try{
            Player player = Manager.createPlayer(new MediaLocator(mp3file.toURI().toURL()));
            player.start();
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
...

Thursday, December 19, 2013

How to List All Installed Applications From the Command Line

One simple command to list all installed application :
wmic product

We can also save them into the .csv file with this comamnd :
wmic product get /format:csv > Software_%Computername%.csv

If this command failed with this error : Invalid XSL format (or) file name.
You should change the Regional and Language to English (US) and re-run the command it should be generated file like : Software_COMPUTERNAME.csv

Reference : http://www.sepago.de/e/helge/2010/01/14/how-to-list-all-installed-applications-from-the-command-line

Friday, October 25, 2013

Grails GORM mapping id column using sequence

I work with grails 2.2.4 and legacy database. The legacy database is using postgreSQL. The primary key filed is hdsj_id (bigserial).


class TableHeaderSuratJalan {

 // a lot of field
 ...

 static mapping = {
  id column: "hdsj_id", generator: "sequence", params: [sequence:"table_header_surat_jalan_hdsj_id_seq"]
  version false
 }

}



We need to specify the sequence name, in this example my sequence's name is table_header_surat_jalan_hdsj_id_seq. By default grails will use hibernate_sequence

Tuesday, October 15, 2013

Setting max limit java heap/memory

In windows 7 create environment variable like this : 


My environment :

  • OS : Windows 7
  • JDK : JDK 7 from oracle

Thursday, September 26, 2013

How to change Grails default port

If we run : grails run-app
By default the grails will listen at port : 8080

We can change by default port by run this command :
grails run-app -Dserver.port=9000
This command will make the grails listen to the port 9000

Another way is by editing the BuildConfig.groovy
Add the following line :
grails.server.port.http = 9000

NB: I use grails 2.2.4

Monday, September 2, 2013

Friday, August 30, 2013

Enable .NET 4 on IIS 6

After installing .NET Framework 4, IIS 6 is not directly enable the .NET 4. Run this command to check : 

cd \windows\system32\
iisext.vbs /ListFile


I got a problem when enable .NET 2 and .NET 4 simultaneously. So, I disable the .NET 2 and enable the .NET 4, by run this command :

C:\WINDOWS\system32>iisext.vbs /disfile C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll



C:\WINDOWS\system32>iisext.vbs /EnFile C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

Restart IIS and the .NET 4 should be work.