• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem stopping audio in using sun.audio package

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any chance this could be a Serializable issue?
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic