After the deployment to the server, no sound is played!

There is java bean

 import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

@Named
public class AudioPlayer {

    AudioPlayer player = new AudioPlayer();

    private File file;
    private String path;

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }



    public void run() {
        player.setPath("Путь до файла");
        file = new File(path);
        AudioInputStream audioIn;
        try {
            audioIn = AudioSystem.getAudioInputStream(file);
            Clip clip;
            clip = AudioSystem.getClip();
            clip.open(audioIn);
            clip.setFramePosition(0);
            clip.start();
            Thread.sleep(clip.getMicrosecondLength() / 1000);
            clip.close();

        } catch (IOException | LineUnavailableException | InterruptedException | UnsupportedAudioFileException ex) {
            Logger.getLogger(AudioPlayer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

There is an XHTML file that should start sound

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >="http://www.w3.org/1999/xhtml"
      >:h="http://>
      >:ui="http://>
      >:f="http://>>
<h:body>
        <h:commandLink action="#{audioPlayer.run}" value="Play" />
</h:body>
</html>

Actually the assembly, the start of the server, deploy without errors, the paths are also correct, but the sound does not play, help!

Asked on January 19, 2020 in Programming.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.