Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Play audio file(s) in Java!  (Read 5105 times)
0 Members and 2 Guests are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: August 26, 2007, 07:43:23 PM »

Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. // Author List:
  3. //      deAppel <Creator>
  4. //
  5. // Description:
  6. // Play audio file using sun.audio package
  7. //
  8. // Environment:
  9. //      This software was developed using Eclipse and Java 1.6
  10. //
  11. // Copyright Information:
  12. //      Copyright (C) 2007      <Institution><None>
  13. // Ark de Appel www.engineeringserver.com
  14. //
  15. //----------------------------------------------------------------------*/
  16.  
  17. import java.awt.Container;
  18. import java.awt.event.ActionEvent;
  19. import java.awt.event.ActionListener;
  20. import java.io.FileInputStream;
  21. import java.io.IOException;
  22.  
  23. import javax.swing.JButton;
  24. import javax.swing.JFrame;
  25.  
  26. import sun.audio.AudioPlayer;
  27. import sun.audio.AudioStream;
  28.  
  29. public class PlayAudio extends JFrame implements ActionListener{
  30. JButton button;
  31. boolean stop = true;
  32.  
  33. public PlayAudio(){
  34. Container c = getContentPane();
  35. button = new JButton("Play");
  36. button.addActionListener(this);
  37. c.add(button);
  38.  
  39. setTitle("Play audio");
  40. setSize(200,100);
  41. setVisible(true);
  42. }
  43.  
  44. public void actionPerformed(ActionEvent e){
  45. try{
  46. AudioPlayer p=AudioPlayer.player;
  47. AudioStream as =
  48. new AudioStream(new FileInputStream("your file here"));
  49. p.start(as);
  50. }
  51. catch(IOException IOE){}
  52. }
  53.  
  54. public static void main(String[] args){
  55. PlayAudio PA = new PlayAudio();
  56. }
  57. }
  58.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #1 on: June 11, 2009, 12:41:31 PM »

Code:
could not create audio stream from input stream

what file extensions does this support? I'm using MP3

Thanks, Koâk  pompom
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #2 on: June 11, 2009, 12:52:59 PM »

Code:
could not create audio stream from input stream

what file extensions does this support? I'm using MP3

Thanks, Koâk  pompom

Woah, thats quite an old topic. I believe *.au files. If you want to play MP3's take a look at the JMF (Java Media Framework)

Take a look here with example code to play mp3 files. http://www.engineeringser...p3javadecoder-t298.0.html
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #3 on: June 11, 2009, 12:53:59 PM »

Woah, thats quite an old topic. I believe *.au files. If you want to play MP3's take a look at the JMF (Java Media Framework)

Take a look here with example code to play mp3 files. http://www.engineeringser...p3javadecoder-t298.0.html


Allright, I'll take a look ^^,

Thanks!
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #4 on: June 11, 2009, 12:56:05 PM »

Allright, I'll take a look ^^,

Thanks!

Np, nice to have you here. I also noticed you are new so uhm, welcome to javaforums.net wink
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #5 on: June 11, 2009, 12:58:40 PM »

Np, nice to have you here. I also noticed you are new so uhm, welcome to javaforums.net wink

Yeah, thanks! Happy

btw, a small question, do you own this forum?
and another one: are you dutch? I am ^^,
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #6 on: June 11, 2009, 01:03:43 PM »

Yeah, thanks! Happy

btw, a small question, do you own this forum?
and another one: are you dutch? I am ^^,

Yes i'm one of the admins, and yes im also from the netherlands but this is an international community for java developers (though we also have .NET boards) so we post in english.

How you found this forum?
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #7 on: June 11, 2009, 01:06:01 PM »

Yes i'm one of the admins, and yes im also from the netherlands but this is an international community for java developers (though we also have .NET boards) so we post in english.

How you found this forum?

Allright, I like English Happy
I found this forum via Javaprogrammingforums.com, someone there posted something that I read and in his signature was the link to engineeringserver.com and via that forum I found this forum xD long story
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #8 on: June 11, 2009, 01:09:26 PM »

Allright, I like English Happy
I found this forum via Javaprogrammingforums.com, someone there posted something that I read and in his signature was the link to engineeringserver.com and via that forum I found this forum xD long story

Ah, those guys banned the account of one of our staff members because they couldn't take it that we were having more post/members i think and probably better java discussions than at their site. Atleast thats what i was told after he got a "banned" message for no reason when trying to login.
« Last Edit: June 11, 2009, 01:11:25 PM by HappyFace » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #9 on: June 11, 2009, 01:10:44 PM »

Ah, those guys banned the account of one of our staff members because they couldn't take it that we were having more post/members i think and probably more higher end discussions. Atleast thats what i was told after he got a "banned" message for no reason when trying to login.
Allright, I'm just happy that I found this forum
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #10 on: June 11, 2009, 01:12:52 PM »

Allright, I'm just happy that I found this forum

=) , we have a few other members here that ditched their forums and joined here as well but i forgot their members names. I'm sure you will notice their usernames here if you are on their forums as well.


As for me, i don't go there.

//edit
i don't think this conversation has much to do with playing mp3 files so lets continue the convo somewhere else (in the general chat or something) if you want?
« Last Edit: June 11, 2009, 01:14:41 PM by HappyFace » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Koâk
Member
*

Reputation: 0
Offline Offline
Posts: 13
Referrals: 0

Awards
« Reply #11 on: June 11, 2009, 01:13:34 PM »

Allright, I hope this community gets bigger Happy
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #12 on: June 11, 2009, 01:15:32 PM »

Allright, I hope this community gets bigger Happy

Well, you joined so thats the first step. May many others follow you wink
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Verlor
Junior Member
*

Reputation: 0
Offline Offline
Posts: 1
Referrals: 0

Awards
« Reply #13 on: November 16, 2009, 03:58:10 PM »

hey man
thank you!!
thats very simple and useful
 thumbsup worship
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #14 on: November 16, 2009, 07:05:12 PM »

hey man
thank you!!
thats very simple and useful
 thumbsup worship

Thanks, glad to help out. I only wish that there are more people active here.. :/
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here