0

I've got a problem with this Code.. I tried to play some sound, which is in the Musik directory in Eclipse. I already tested, if the sound exist, can be read, and can be opened. All looks ok. But I can't hear anything.

package mhm;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static void main(String[] args) {
        new Main();
    }

    URL url = null; 
    AudioClip clip;
    File file = new File("Musik/VOWZN-UnRational.wav");

    public Main() {
        try {
            url = new URL("file://" + file.getPath());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } 
        clip = Applet.newAudioClip(url);
        clip.play();
        new Menu();
    }
}

On Runtime, there aren't any errors..

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

1 Answers1

1

That code should not work in an (untrusted) applet. It is trying to access a file in the local filesystem (via a "file:" URL), and sandbox security should block that.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thank you. Do you have some suggestion, how i can solve my problem? – user3128014 Dec 22 '13 at 22:42
  • Access the audio clip from a remote URL on the same site you launch the applet from, embed the audio clip in the applet JAR file (and access via the classpath), or don't use applets at all. (The last is the best solution from the perspective of end-user security.) – Stephen C Dec 22 '13 at 23:41
  • And how shall I play the audio clip without an applet? Thanks for your help :) – user3128014 Dec 23 '13 at 11:26
  • Try this Answer to a related Question: http://stackoverflow.com/a/5724541/139985 – Stephen C Dec 23 '13 at 13:21