aspose file tools*
The moose likes Applets and the fly likes Apple + sound + permission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Apple + sound + permission" Watch "Apple + sound + permission" New topic
Author

Apple + sound + permission

Carsten Rasmussen
Ranch Hand

Joined: Sep 22, 2009
Posts: 65
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
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
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.


Ping & DNS - my free Android networking tools app
Carsten Rasmussen
Ranch Hand

Joined: Sep 22, 2009
Posts: 65
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

Joined: Sep 22, 2009
Posts: 65
Maybe you could explain me howto make a java policy file that would be a good help.
thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
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

Joined: Sep 22, 2009
Posts: 65
EHmm, how do i get the console in ubuntu linux ???
thanks by the way
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
Like this: http://www.java.com/en/download/help/5000021200.xml
Carsten Rasmussen
Ranch Hand

Joined: Sep 22, 2009
Posts: 65
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

Joined: Sep 22, 2009
Posts: 65
Im using this code:

What is wrong what is it I'm doing wrong/missing ???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
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

Joined: Sep 22, 2009
Posts: 65
"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
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
You could open a popup window that displays the stack trace.
Carsten Rasmussen
Ranch Hand

Joined: Sep 22, 2009
Posts: 65
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
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apple + sound + permission