Thread: Playing mp3's in your client

Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1 Playing mp3's in your client 
    ¯̿ ̿|̿ ̿ |̶ ̶ ̶ ̶| |̶͇̿ ̶͇̿ ͇̿ Haskelle

    Join Date
    Nov 2007
    Age
    26
    Posts
    1,228
    Thanks given
    329
    Thanks received
    517
    Rep Power
    1133
    Files needed: [Only registered and activated users can see links. ]

    step 1: add this in a new notpad file and save as MP3.java
    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.
     * original source: http://www.cs.princeton.edu/introcs/faq/mp3/MP3.java.html
     *  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();
    
        }
    
    }
    step 2:
    to use it use
    Code:
    mp3 = new MP3(yourmp3.mp3);
            mp3.play();
    not much of a tutorial but it is a base that you can use

    resources: [Only registered and activated users can see links. ]
    Monads are just Monoids in the category of Endofunctors. What is the problem?
    Costate Comonad Coalgebra is equivalent of Java's member variable update technology for haskell. Problem?
    Reply With Quote  
     

  2. #2  
    Fuckin PRO

    Damien's Avatar
    Join Date
    Feb 2008
    Age
    29
    Posts
    2,658
    Thanks given
    928
    Thanks received
    82
    Rep Power
    369
    i love this tut!! I love listening to music on my clients and btw thanks!
    Reply With Quote  
     

  3. #3  
    Horsecockinmyass
    Guest
    ........lol nj..i hases already..u add to jframe? as buttons?
    Reply With Quote  
     

  4. #4  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,881
    Thanks given
    1,854
    Thanks received
    4,741
    Rep Power
    5000
    Hehe I remember when you asked me to test this for you



    Reply With Quote  
     

  5. #5  
    Community Veteran


    Join Date
    Jul 2006
    Posts
    294
    Thanks given
    21
    Thanks received
    14
    Rep Power
    174
    Arian rock, please use the tutorial layout or this will be removed.
    [Only registered and activated users can see links. ]
    [Today 10:44 PM] Uzi: I wish i hadz sexz
    [Today 10:44 PM] Uzi: But no no N0 i had to go to a boys only college
    Reply With Quote  
     

  6. #6  
    Registered Member Spoonz's Avatar
    Join Date
    Dec 2007
    Age
    27
    Posts
    90
    Thanks given
    4
    Thanks received
    0
    Rep Power
    26
    Could you explain it abit more please, like how to add it >.>

    Im vary noobish, basically i added it but idk how to add the mp3 or anything.

    PL0x explain further ive been searching how to add a start up tune for ages.

    OR even adding amusic player, i know nothing


    Reply With Quote  
     

  7. #7  
    ¯̿ ̿|̿ ̿ |̶ ̶ ̶ ̶| |̶͇̿ ̶͇̿ ͇̿ Haskelle

    Join Date
    Nov 2007
    Age
    26
    Posts
    1,228
    Thanks given
    329
    Thanks received
    517
    Rep Power
    1133
    Quote Originally Posted by Drags View Post
    Arian rock, please use the tutorial layout or this will be removed.
    [Only registered and activated users can see links. ]
    this isnt really a tutorial
    just a java file that people may want to use
    Monads are just Monoids in the category of Endofunctors. What is the problem?
    Costate Comonad Coalgebra is equivalent of Java's member variable update technology for haskell. Problem?
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Sep 2007
    Posts
    1,394
    Thanks given
    3
    Thanks received
    2
    Rep Power
    323
    Nice tut/Java file great job.
    Reply With Quote  
     

  9. #9  
    Banned
    Join Date
    Jul 2008
    Posts
    458
    Thanks given
    5
    Thanks received
    11
    Rep Power
    0
    This is pretty good put which folder do we put our MP3 file into?
    Reply With Quote  
     

  10. #10  
    Registered Member
    cocoa's Avatar
    Join Date
    Jan 2008
    Age
    26
    Posts
    652
    Thanks given
    4
    Thanks received
    22
    Rep Power
    200
    Quote Originally Posted by Netgear137 View Post
    This is pretty good put which folder do we put our MP3 file into?
    just with all the rest of the unless you make one called like music then it would be

    (music/yourmusicname.mp3);
    Project 377
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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