File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apple + sound + permission

 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having problems playing sound in my first applet please help.

This is the code i use:


And i get this error:
Access denied (Java.lang.RuntimePermission getProtectionDomain)

I have tried and google it and i seems like it is a permission rights on file problem.
How do i fix that i cant find an example.

Thanks in advanced,
Carsten S. Rasmussen

It might be a newbie question but its relevant, at least for me :O)
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, this is a bad idea: catch (Exception e) { }. At least log an error message so that you know that a problem occurred.

Secondly, applets have no access to the local file system. Assuming that you intend the audio file to be loaded from the server (where the applet resides), the URL must be an "http://..." URL.

If the file really is on the local file system (which would be very strange for an applet, which are not generally allowed to access to it for good reasons), see HowCanAnAppletReadFilesOnTheLocalFileSystem.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my url is http://localhost/sounds/send.wav how do i add that i tried just now and applet wont run:


I checked that the file is there and its working but still i cant play it.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could explain me howto make a java policy file that would be a good help.
thanks.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's odd, the code should work. In an applet you should use getAudioClip(...), not Applet.newAudioClip(...), by the way.

In the Java Console, can you see the audio file being successfully downloaded, with no error messages?

Maybe you could explain me howto make a java policy file

No policy file (or signed applet) is needed since the file now comes from the same server that hosts the applet.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EHmm, how do i get the console in ubuntu linux ???
thanks by the way
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this: http://www.java.com/en/download/help/5000021200.xml
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i install self extracting java i will overide package default-java isn't there another way to tell if sound is downloaded maybe an applet code.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using this code:

What is wrong what is it I'm doing wrong/missing ???
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you're saying about "self extracting Java". There's probably an exception in the Console.

Alternatively, you can check the web server access logs to see if the file is accessed and served properly.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"self extracting java" is a way to add java in Ubuntu. I have no console.
I have no logs, isn't there a solution within the code ?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could open a popup window that displays the stack trace.
 
Carsten Rasmussen
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know howto do that, but i did this code:

And the sound played perfectly. So how do i play sound in web applet ???
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you had before is fine, there's no need to change it. As I said, there's probably an exception, so you need to find a way to log or display it. I recommend you search for how to enable the Java Console on your system.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic