在Java中音乐循环 [英] Music Loop in Java

查看:295
本文介绍了在Java中音乐循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我在做一个游戏,我希望它有一个背景声音。我创建了它一个类我把它放在我的主。我的code是如下:

I am doing a game and I want it to have a background sound. I created a class for it and I call it on my main. My code is as follows:

import sun.audio.*;
import java.io.*;

    public class Sound {

        public void music() {

            AudioStream backgroundMusic;
            AudioData musicData;
            AudioPlayer musicPlayer = AudioPlayer.player;
            ContinuousAudioDataStream loop = null;
            try {
                backgroundMusic = new AudioStream(new FileInputStream("chickendance.wav"));
                musicData = backgroundMusic.getData();
                loop = new ContinuousAudioDataStream(musicData);
                musicPlayer.start(loop);
            } catch (IOException error) { System.out.println(error);
            }
        }
    }

这是我的主课堂,我把它叫做

This is my main class where i call it.

public class HangmanLauncher extends javax.swing.JFrame {

        public HangmanLauncher() {
            initComponents();
            Sound sound = new Sound();
            sound.music();
        }

我的问题是,音乐不能播放。 错误:java.io.IOException异常:无法创建从输入流音频流是什么意思?类型我的文件是微软波形声音格式,其大小为796KB。我可以知道我做错了什么?您的建议将是非常美联社preciated。谢谢你在前进。

My problem is that the music doesn't play. Error: java.io.IOException: could not create audio stream from input stream. What does it mean? The type of my file is Microsoft Wave Sound Format and its size is 796kb. May I know what I am doing wrong? Your suggestions will be highly appreciated. Thank you in advance.

推荐答案

我的猜测是, WAV 文件已经连接$ C $光盘的格式语音串流类不明白。我找不到的类(?)的文档,但我会尝试另一个文件不是微软波形声音。同样,不知道编码的具体细节,但它是微软它可能是私有的,因此不能在阳光下实施语音串流

My guess is that the wav file has been encoded in a format the AudioStream class doesn't understand. I couldn't find the docs for the class (??) but I would try another file that isn't Microsoft Wave Sound. Again, don't know the specifics of that encoding but it being Microsoft it's probably proprietary and therefore not in the Sun implementation of the AudioStream.

这篇关于在Java中音乐循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆