Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to play Audio file?

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to play Audio file?

    How to write a program that plays audio file? Audio is stored in folder.


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: How to play Audio file?

    Have you tried this ?

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to play Audio file?

    ya i am tried like:

    public class PlayMp3 extends Thread
    {



    private URL url;

    public PlayMp3(File mp3)

    {

    this.url = mp3.toURL();}

    public void run()

    {

    try

    {


    MediaLocator ml = new MediaLocator(url);
    Player player = Manager.createPlayer(ml);
    player.addControllerListener
    (

    new ControllerListener()


    { public void controllerUpdate(ControllerEvent event)

    { if (event instanceof EndOfMediaEvent)
    { player.stop(); player.close();
    }
    }
    }

    );
    player.realize();player.start();

    }
    catch (Exception e)

    {e.printStackTrace();
    }
    }

    }
    }

    But its showing error at : medialocator, think hav to add audio jar file .

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,541
    My Mood
    Hungover
    Thanks
    145
    Thanked 648 Times in 553 Posts

    Default Re: How to play Audio file?

    Erm, can Java handle mp3s like that, without using a library?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Audio In My Program
    By Fordy252 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 08:46 AM
  2. Sounds to play during action performed
    By smithyboy in forum Object Oriented Programming
    Replies: 2
    Last Post: November 20th, 2010, 04:16 PM
  3. Audioclip play makes applets slow
    By Marcus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 01:20 PM
  4. Java refuses to play sound on my machine
    By DDgeva in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: January 31st, 2010, 08:58 AM
  5. sun.audio
    By bguy in forum Java SE APIs
    Replies: 3
    Last Post: November 12th, 2009, 01:17 AM