Question about Computers & Internet

1 Answer

How to play audio clip in java - Computers & Internet

Posted by on

1 Answer

  • Level 3:

    An expert who has achieved level 3 by getting 1000 points

    All-Star:

    An expert that got 10 achievements.

    MVP:

    An expert that got 5 achievements.

    President:

    An expert whose answer got voted for 500 times.

  • Master
  • 1,952 Answers

  • Create an AudioClip object
  • Load .au sound file into AudioClip
  • Play sounds once or loop continuously
  • Stop playback


Here's how the code for these steps looks:
import java.applet.*;
AudioClip ac = getAudioClip(getCodeBase(), soundFile);
ac.play(); //play once
ac.stop(); //stop playing
ac.loop(); //play continuously


It would seem logical to use this same code to play audio clips in a Java application. Unfortunately, if you do that you will get errors from the compiler. Why? Because the AudioClip object and the getAudioClip() method are part of the java.applet package -- and are not part of applications. The good news is we can dive down and make things work ourselves.
The trick to solving this problem is to use some undocumented features that are provided by Sun in its JDK. Taking a peek inside the classes.zip file from the Sun JDK (using any of the various zipfile utilities), we find not only the standard Java packages such as java.applet but also sun.audio. (These are in the directory sun/audio.)
The sun.audio package contains everything we need to be able to play audio clips! Here's the code:
import sun.audio.*; //import the sun.audio package
import java.io.*;
//** add this into your application code as appropriate
// Open an input stream to the audio file.
InputStream in = new FileInputStream(Filename);
// Create an AudioStream object from the input stream.
AudioStream as = new AudioStream(in);
// Use the static class member "player" from class AudioPlayer to play
// clip.
AudioPlayer.player.start(as);
// Similarly, to stop the audio.
AudioPlayer.player.stop(as);


To use a URL as the audio stream source, substitute the following for the input stream and audio stream setup:
AudioStream as = new AudioStream (url.openStream());


Playing the audio stream continuously adds a bit more complexity:
// Create audio stream as discussed previously.
// Create AudioData source.
AudioData data = as.getData();
// Create ContinuousAudioDataStream.
ContinuousAudioDataStream cas = new ContinuousAudioDataStream (data);
// Play audio.
AudioPlayer.player.play (cas);
// Similarly, to stop the audio.
AudioPlayer.player.stop (cas);

Posted on Jan 22, 2009

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

Multi audios play at same time


The only issue this has been reported as a bug with was with a recent java plug-in update. Please try updating Java or removing it completely and reinstalling.

Oct 19, 2012 | Apple MacBook Air

1 Answer

I am 13 and it won't let me play We Doodle, I really like this game so please fix this for me.


Install JAVA from here:

http://www.java.com/en/download/index.jsp


Or try upgrading your graphic driver.

Why download Java? Java technology allows you to work and play in a secure computing environment.
Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.
After you've downloaded Java, visit java.com to check out Java in Action in your daily life.

Hope this will help

Mar 10, 2011 | Computers & Internet

2 Answers

My sound is not work..i instaled the driver, at realtek manager demo i hear, but at movie, song, or youtube..not work...i have motherboad asusM2A-VM ...ty


I hate to say it, but I often run into problems with my audio dying when I'm attempting to adjust the audio properties on a flash-based video stream. The only way I can get it to reset without rebooting is to throw my PC into "Stand By" and then bringing it back out of it. This resets all of the multimedia hardware on my PC. It's crude, but it works.

Mar 02, 2011 | Computers & Internet

1 Answer

How do i play whats on the memory card nothing plays video only audio. or what do i need to convert it


First, make sure you have it on CARD (and not DISK), and on the "playback" (and not record) mode. Next, does the camera play back other video clips normally, but just not a specific clip ?
Does the selected video clip frame (index) shown on the LCD screen have a picture ? If not, i.e. it is blank (dark), then it is likely that no video was recorded (i.e. just the audio) when you were shooting that video clip.
If there is a picture (of the video clip frame index on the LCD screen) and only audio is playing, try downloading the clip (from the SD card) to your computer, or simply try to play the video on the SD card (inserted directly into your SD card reader on your computer, or via a USB SD card reader) and see if the video clip will play normally on your computer.

Jan 09, 2011 | Samsung SC-DC173 DVD Camcorder

1 Answer

Machine will not show graphics after working properly for 15 minutes.


This course uses  (Java applets  (Suns' Java technology)  In older version of Microsoft internet Browser the Microsoft Virtual  is already installed in your machine.   In newer version of windows installation, the Java  is  not install automatically.  In most cases, now you must install the Java separately into your machine  http://java.com/en/index.jsp  (download free Java software)

DursulQuran is also available in "Printed version", in theory does not require a computer and the course may be follow independently by using a booklet.   In addition,  the sound of each lessons have been recorded that may be run from stand alone CD player as well the audio cassettes.   The course material may be downloaded freely from this site.   The printed material are prepared in Acrobat Pdf. format and easily printable on 8.5 x 11 paper.  the sound clips are in MP3 format that can be burned into a audio CD (and latter transfer into an audio cassette) as well as run in your hard disk. 
Obtain Printed version click here

Dec 02, 2010 | GPX Audio Players & Recorders

1 Answer

Sansa Clip 4GB...no audio when playing songs ...FM audio fine


the mp3 audio driver may be missing and system needs to be updated.

Jul 09, 2009 | SanDisk Sansa Clip MP3 Player

2 Answers

My i68+ sciphone isnt playing mp3 music.


first you need to make sure you copy your music into the Audio folder on your sd card. make sure it is on the sd card and not the pdones memory. it will come up as two drives. you should be able to go to your documents icon then to the AUDIO folder find the song you want to play click on it then click PLAY. This will open the Audio player. to add a playlist from the audio player click on the list text at bottom left of the audio palyer. go to LIST>it will show the one song that is cued up go to >OPTIONS>ADD> go back to the Audio folder click on each song you want to add it will say done.

as for java you have to download .jar files i have a cd for sale that has hundreds of java games and a few java apps. to install them it is basically the same as you music. make a new folder on you sd card name it whatever you like say GAMES. go to the documents icon go to memory card go to the folder like games. find the .jar file you are going to install click on it, it will give you the install option and is self expalnatory from there.

For full help topics I have a cd available for 10 us dollars. Has 100's of mp3 ring tones wallpapers, and java games and opera java browser. Guaranteed help on every question ever asked on these phones. And all settings for all cellular services. I have answered 100 questions with this CD. If interested contact prestorose@aol.com Pay Pal only, will send out First CLASS Mail in padded envelope. If interested I will send Pay-Pal invoice that can be filled out and returned with instructions. Guaranteed safe transaction.

May 05, 2009 | AT&T CECT Unlocked i68+ Quadband GSM FM...

1 Answer

Firefox web browser can not play video and audio on the player


try installing the shockwave player from foxfire at
http://get.adobe.com/shockwave/

and java at www.java.com

some web sites require this to play video & music from there site like youtube

Oct 01, 2008 | Acer Extensa 503T Notebook

1 Answer

File fomat


video-Watch MPEG 4 video clips in bright colour with 22kHz polyphonic speaker sound. with 3D graphics engine audio- MP3 format/wav/amr games- 3D java games /Java™ MIDP 2.0 for full details download pdf file from from link below. http://www.motorola.com/mot/doc/1/1525_MotDoc.pdf

Aug 18, 2007 | Motorola Mobility RAZR V3

2 Answers

Problem playing new audio tracks


Is the files in any way DRM-protected content ?

Aug 12, 2007 | Sony Ericsson K750i Cellular Phone

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

288 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...