aspose file tools*
The moose likes Java in General and the fly likes Problem stopping audio in using sun.audio package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem stopping audio in using sun.audio package" Watch "Problem stopping audio in using sun.audio package" New topic
Author

Problem stopping audio in using sun.audio package

Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
I'm currently using the sun.audio package to play audio files in my application composed of servlets and jsps, code would be something simple as follows in my servlet

My application has a number of tabs, the tab for playing audio for example, is called audioPlay and contains the code above. My problems are:
(1) selecting a different browser tab, while audio is playing, within my application, the audio still continues playing, I cannot stop it.
(2) Selecting the back browser on the web application, while the audio is running, the audio doesn't stop and is still running.
I've seen on a number of web-sites that clicking on a song title, goes into a servlet and plays the song in background which is what I have presently, but when they do steps 1 and 2 above within their website, the audio stops but doesn't in mine, are there any suggestions about how to solve this? I need to call Audioplayer.player.stop(as) at some stage, would using a class with static variables and start and stop options be a possibility? I hope I have made my issue clear or could this be an issue with the cache-control header? Thanks for any help returned.


Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
Where did you get the classes like AudioStream and AudioPlayer. Do you have another jar?
I know one package from sun that is Java Sound API (previously it used to get included in JMF - Java Media Framework). Not very sure, but I think now it comes along with SDK itself.
You can read more about it here.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Thanks Akhilesh,
I've tried that package, thanks for advice, the sun.audio only works up to 16 bit audio, no problem with the Java Sound API. I have audio streaming on my localhost computer on my localhost website but now I have an issue when I try to point to the file from a different pc, meaning trying to access the web-site from a different computer through the web, nothing is happening I can't get the sound file to play. I have a servlet like this to point to the file

And a class to run this file, but no sound plays when trying to access file, from different PC through ip address of hosting PC. This does load and play on the Pc where the sound file is hosted, by using localhost.

This could be a generic issue just as well. Any help much appreciated.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408

This is not a good idea. How will you know if there's a problem? At least log the error message somewhere where you'll see it.
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Thanks Tim. I have those error checks in my servlet that calls the class to stream the audio, but no errors are created. There's no problem running the project on my local Pc and the sound plays grand in the application, it's just when accessing the web-site from different PC, it is like the file is not loading and playing, I get no sound. Is there any chance it is an issue with the sound player used by the package "javax.sound.sampled"? As regards not being a good idea, any other alternatives or suggestions are extremely appreciated, thanks very much.
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Any chance this could be a Serializable issue?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

If your servlet is starting the sound then it will run on the server, not on the client / in the browser. To run it in the browser you need a) an applet where you can use its methods to start / stop the sound, b) embed it using HTML5's <audio> tag, or c) use the "old" <embed> tag to embed it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem stopping audio in using sun.audio package
 
Similar Threads
Problem playing sound from application
AudioPlayer issues
Sound problem in Java
How do I loop the sound file in this program>
Playing wav - java.io.FileNotFoundException when file is def there