小编use*_*117的帖子

声音在java中 - 游戏在播放声音时冻结

每当我在游戏中播放声音时,线程会在声音播放结束后冻结然后继续.声音引擎代码:

package com.kgt.platformer;

import java.io.File;
import java.io.IOException;    
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

public class Sound {
    private final static int BUFFER_SIZE = 12800000;
    private static File soundFile;
    private static AudioInputStream audioStream;
    private static AudioFormat audioFormat;
    private static  SourceDataLine sourceLine;

    /**
     * 
     * @param filename the name of the file that is going to be played
     *
     */
    public static void playSound(String filename){

        String strFilename = filename;

        try {
            soundFile = new File(strFilename);
        } …
Run Code Online (Sandbox Code Playgroud)

java audio javasound

0
推荐指数
1
解决办法
2872
查看次数

标签 统计

audio ×1

java ×1

javasound ×1