Results 1 to 2 of 2

Thread: [ask]Java

http://idgs.in/198943
  1. #1
    white_luck's Avatar
    Join Date
    May 2007
    Location
    surabaya
    Posts
    635
    Points
    917.42
    Thanks: 4 / 0 / 0

    Default [ask]Java

    kk yang menguasai OOP
    mohon bantuan

    gmn cara ngasi lagu d program ya?
    thanks a lot
    Last edited by bl00d13z; 23-05-09 at 18:27.
    Code:
    Konfirmasi ID : http://goo.gl/iybJo

  2. Hot Ad
  3. #2

    Join Date
    May 2008
    Location
    /proc/sys/kernel/randomize_va_space
    Posts
    875
    Points
    1,326.90
    Thanks: 0 / 13 / 8

    Default

    di java ya.. doh gw ga pernah maen2 java T.T
    coba gini:

    Code:
    /*************************************************************************
     *  Compilation:  javac -classpath .:jl1.0.jar MP3.java         (OS X)
     *                javac -classpath .;jl1.0.jar MP3.java         (Windows)
     *  Execution:    java -classpath .:jl1.0.jar MP3 filename.mp3  (OS X / Linux)
     *                java -classpath .;jl1.0.jar MP3 filename.mp3  (Windows)
     *  
     *  Plays an MP3 file using the JLayer MP3 library.
     *
     *  Reference:  http://www.javazoom.net/javalayer/sources.html
     *
     *
     *  To execute, get the file jl1.0.jar from the website above or from
     *
     *      http://www.cs.princeton.edu/introcs/24inout/jl1.0.jar
     *
     *  and put it in your working directory with this file MP3.java.
     *
     *************************************************************************/
    
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    
    import javazoom.jl.player.Player;
    
    
    public class MP3 {
        private String filename;
        private Player player; 
    
        // constructor that takes the name of an MP3 file
        public MP3(String filename) {
            this.filename = filename;
        }
    
        public void close() { if (player != null) player.close(); }
    
        // play the MP3 file to the sound card
        public void play() {
            try {
                FileInputStream fis     = new FileInputStream(filename);
                BufferedInputStream bis = new BufferedInputStream(fis);
                player = new Player(bis);
            }
            catch (Exception e) {
                System.out.println("Problem playing file " + filename);
                System.out.println(e);
            }
    
            // run in new thread to play in background
            new Thread() {
                public void run() {
                    try { player.play(); }
                    catch (Exception e) { System.out.println(e); }
                }
            }.start();
    
    
    
    
        }
    
    
        // test client
        public static void main(String[] args) {
            String filename = args[0];
            MP3 mp3 = new MP3(filename);
            mp3.play();
    
            // do whatever computation you like, while music plays
            int N = 4000;
            double sum = 0.0;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    sum += Math.sin(i + j);
                }
            }
            System.out.println(sum);
    
            // when the computation is done, stop playing it
            mp3.close();
    
            // play from the beginning
            mp3 = new MP3(filename);
            mp3.play();
    
        }
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •