如何使用interrupt()

时间:2018-03-18 01:40:27

标签: java interrupt

我使用Java制作游戏,但我不能使用interrupt()函数。它说interrupt()函数是未定义的。

这是代码。我该怎么做才能解决这个问题?

P.S。我想有人说错误是因为(跳过),但我认为你没有抓住问题的含义。

我发现了错误。感谢您的评论!

package beat_the_beat_1_0;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import javazoom.jl.player.Player;

public class Music {

    private Player player;
    private boolean isLoop;
    private File file;
    private FileInputStream fis;
    private BufferedInputStream bis;

    public Music(String name, boolean isLoop) {
        try {
            this.isLoop = isLoop;
            file = new File(Main.class.getResource("../music/" + name).toURI());
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            player = new Player(bis);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public int getTime() {
        if(player == null)
            return 0;
        return player.getPosition();
    }

    public void close() {
        isLoop = false;
        player.close();
        this.interrupt(); // Here is the error.
    }

    @Override
    public void run() {
        try {
            do {
                player.play();
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                player = new Player(bis);
            } while(isLoop);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}

0 个答案:

没有答案