xiaoxing tech

September 25, 2008

lrc Music Player

Filed under: JME — xiaoxing @ 10:14 pm

This is my pet project:
a Java ME app, play audio files while displaying
.lrc format lyrics. The structure is based on the Sun WTK demo
Currently it hasn’t been tested on real device, simply because I don’t have a “modern” enough device……
While it is working great on the Sun emulator.

Features:

1. Use Left, Right direction keys to move the highlighting spot on the control panel. On the figure above, the spot is on the “Pause” button, so you can move it to “Play” button then press fire button to start the music.

2. Normally three lines of lyric are shown when music is playing. The current singing one is highlighted.

3. The right most button is “Open”. Fire it to open the file browser. This feature requires File Connection API (JSR 75). It looks like this:

You select a file to play. Supported formats include: midi, kar, wav, amr. Although unfortunately Sun’s emulator doesn’t support MP3, lots of real phones do.

4. The location of a file that is played will be saved into RMS upon exiting the app. By using “Menu”(right soft key) – “Open Rms”, you can use the RMS browser to check or delete the saved file path.

Finally, the jad and jar. (Use Sun wtk MediaControlSkin to run.) 
And source code.


September 12, 2008

read text file from FileConnection

Filed under: JME — xiaoxing @ 3:17 pm

fc = (FileConnection) Connector.open(lrcFile, Connector.READ);
                    if (fc.exists()) {
                        lrcExists = true;
                        InputStream lrcis = fc.openInputStream();//xxz
                        InputStreamReader r = new InputStreamReader(lrcis, “UTF-8″);
                        char[] buffer = new char[32];//for UTF-8, char is read one by one
                        StringBuffer sb = new StringBuffer();
                        int count;
                        while ((count = r.read(buffer, 0, buffer.length)) > -1) {
                            sb.append(buffer, 0, count);
                        }
//                        lrcLines = sb.toString().split(“\r\n|\r|\n”);//not in jme
                        lrcLines = Utils.splitString(sb.toString().trim(), ‘\n’);
                        System.out.println(“true”);
                    } else {

August 19, 2008

Music, Physics and (JME)Programming

Filed under: JME — xiaoxing @ 3:16 pm

f1. Frequency Values for the Basic Notes

f2. The Different Octaves for the Musical Note A

August 15, 2008

FileConnection optional API: example: Save a web-link file to phone

Filed under: JME — xiaoxing @ 1:26 pm

                // open up web page
                String version = “”;
                try
                {       
                    //test if the phone support FileConnection
                    version = System.getProperty(“microedition.io.file.FileConnection.version”);
                    if (version != null) {
                            if (!version.equals(“1.0″))
                                throw new IOException(“Package is not version 1.0.”);
                       }
                    else
                        throw new IOException(“File connection optional package is not available.”);
                   
                    System.out.println(“fc version is: ” + version);
                       
                                         
                   Thread t = new Thread(){
                       public void run(){
                      //find out the root directory for the phone       
//                           Enumeration drives = FileSystemRegistry.listRoots();
//                           System.out.println(“The valid roots found are: “);
//                           int ct = 1;
//                           while(drives.hasMoreElements()) {
//                               String root = (String) drives.nextElement();
//                               System.out.println(“\t”+root);//root1
//                               debug.debugTools.addMessage(ct, root);
//                               ct++;
//                           }
                           //Samsung A827: filesystem/ and Graphics/
                          
                          
                           //check the content of the root directory
                           String url = “file:///Graphics/MLinks.vbm”;
                           FileConnection wconn = null;
                          
                           try{
//                           FileConnection fc = (FileConnection)Connector.open(“file:///filesystem/”);
//                         // Get a filtered list of all files and directories.
//                         // True means: include hidden files.
//                         // To list just visible files and directories, use
//                         // list() with no arguments.
//                         System.out.println(“List of files and directories under root1:”);
//                         Enumeration filelist = fc.list(“*”, true);
//                         int ct = 1;
//                         while(filelist.hasMoreElements()) {
//                            String fileName = (String) filelist.nextElement();
//                            fc = (FileConnection)Connector.open(“file:///filesystem/” + fileName);
//                            if(fc.isDirectory()) {
//                               System.out.println(“\tDirectory Name: ” + fileName);
//                               debug.debugTools.addMessage(ct, “dir: ” + fileName);
//                            } else {
//                               System.out.println
//                                  (“\tFile Name: ” + fileName +
//                                   “\tSize: “+fc.fileSize());
//                               debug.debugTools.addMessage(ct, fileName + ” size: ” + fc.fileSize());
//                            }
//                            ct++;
//                         }  
//                         if(ct == 1){debug.debugTools.addMessage(ct, “nothing under filesystem”);}
//                         fc.close();
                        
                        
                         //write file to phone
                         wconn = (FileConnection)Connector.open(url, Connector.READ_WRITE );
                         if(wconn.exists()){
                             wconn.delete();   
                             wconn = (FileConnection)Connector.open(url, Connector.READ_WRITE );
                         }
                         if (!wconn.exists()){
                             wconn.create();  // create the file if it doesn’t exist
                             OutputStream out = wconn.openOutputStream();
                             String ourl = “BEGIN:VBM\nVERSION:1.0\nTITLE:MLinks\nURL:http://www.mlinks.com/\nBEGIN:ENV\nX-IRMC-URL;QUOTED-PRINTABLE:=\n[InternetShortcut]URL=3Dhttp://www.mlinks.com/\nEND:ENV\nEND:VBM”;
                             byte[] ourlba = ourl.getBytes();
                             out.write(ourlba);
                             out.flush();
                         }
                         wconn.close();

                           } catch (Exception ioe){
                                System.out.println(“xxz: ” + ioe.getMessage());
                                debug.debugTools.addMessage(6, “xxz: ” + ioe.getMessage());
//                                tUI.mOpenDialog(“Unable to open browser.” + ioe.getMessage(),
//                                        “OK”, null, 0, false);
                               repaint();
                            }
                        
                       }//end of run
                    };
//                        t.setPriority(Thread.MIN_PRIORITY);
                    t.start();
                   
                }
                catch (Throwable t)
                {
                    OpenDialog(“Unable to open browser.” + t.getMessage() + “_” + version,
                            “OK”, null, 0, false);
                    repaint();
                }

July 25, 2008

when paint() is called?

Filed under: JME — xiaoxing @ 10:04 am

Java ME figure: Top-level user interface classes

Filed under: JME — xiaoxing @ 9:52 am

Blog at WordPress.com.