ContinousAudioDataStream

ContinousAudioDataStream

我只是想在这里做一个简单的程序,以便可以尝试将其包含在游戏中。

package practs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import sun.audio.*;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Project1{

    public static void main(String[] args){
        JFrame frame = new JFrame();
        frame.setSize(200,200);
        frame.setLocationRelativeTo(null);
        JButton button = new JButton("Click me");
        frame.add(button);
        button.addActionListener(new AL());
        frame.setVisible(true);
    }

    public static class AL implements ActionListener{
        public final void actionPerformed(ActionEvent e){
            music();
        }
    }

    public static void music(){
        AudioPlayer MGP = AudioPlayer.player;
        AudioStream BGM;
        AudioData MD;

        ContinousAudioDataStream loop = null;

        try{

            InputStream test = new FileInputStream("backgroundMusic.m4a");
            BGM = new AudioStream(test);
            AudioPlayer.player.start(BGM);
            MD = BGM.getData();
            loop = new ContinousAudioDataStream(MD);

        }catch(FileNotFoundException e){
            e.printStackTrace();
        }catch(IOException error){
            error.printStackTrace();
        }
        MGP.start(loop);
    }
}

问题是所有错误(ContinousAudioDataStream除外):
Access restriction: The type 'AudioPlayer' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/jre/lib/rt.jar')

这些错误发生
  • AudioPlayer
  • AudioStream
  • AudioData
  • 这就是ContinousAudioDataStream
  • 发生的情况
  • ContinousAudioDataStream ContinousAudioDataStream cannot be resolved to a type
  • 最佳答案

    如果使用的库不是官方JDK API的一部分,则基本上会发生此错误。您可以在Eclipse首选项中禁用这些警告。


    Windows -> Preferences -> Java -> Compiler -> Errors/Warnings Project -> Properties -> Java Compiler -> Errors/Warnings
    

    现在转到Forbidden reference (access rules)” option under “Deprecated and restricted API
    默认选项设置为error,这限制了此类API的使用。您可以将其更改为警告或忽略,然后清除并构建您的代码。

    或者,您可以尝试从构建路径中删除库,然后将其重新添加到项目中。

    10-05 18:25