捕鱼达人游戏的背景音乐不能加入!求助大神指导

Andy瑞波 2016-07-22 11:45:42
[code=javapackage com.mypro.basecomponet;

/*
* DecodingAudioPlayer.java
*
* This file is part of jsresources.org
*/

/*
* Copyright (c) 1999, 2000 by Matthias Pfisterer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
|<--- this code is formatted to fit into 80 columns --->|
*/

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.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;

public class DecodingAudioPlayer
{
private static final int EXTERNAL_BUFFER_SIZE = 128000;



public static void main(String[] args)
{
// if (args.length != 1)
// {
// printUsageAndExit();
// }
String strFilename = "C:\\Users\\Andy\\Desktop\\hundredpoints.mp3";
File file = new File (strFilename);
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
AudioInputStream audioInputStream = null;
try
{
audioInputStream = AudioSystem.getAudioInputStream(file);
}
catch (Exception e)
{
e.printStackTrace();
}
if (audioInputStream == null)
{
out("### cannot read input file: " + strFilename);
}
AudioFormat sourceFormat = audioInputStream.getFormat();
AudioFormat.Encoding targetEncoding = AudioFormat.Encoding.PCM_SIGNED;
audioInputStream = AudioSystem.getAudioInputStream(targetEncoding, audioInputStream);
AudioFormat audioFormat = audioInputStream.getFormat();

SourceDataLine line = null;
DataLine.Info info = new DataLine.Info(
SourceDataLine.class,
audioFormat);
try
{
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(audioFormat);
}
catch (LineUnavailableException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
line.start();
int nBytesRead = 0;
while (nBytesRead != -1)
{
try
{
nBytesRead = audioInputStream.read(abData, 0, abData.length);
}
catch (IOException e)
{
e.printStackTrace();
}
if (nBytesRead >= 0)
{
int nBytesWritten = line.write(abData, 0, nBytesRead);
}
}
// line.close();
}



public static void printUsageAndExit()
{
out("DecodingAudioPlayer: usage:");
out("\tjava DecodingAudioPlayer <soundfile>");
System.exit(1);
}



private static void out(String strMessage)
{
System.out.println(strMessage);
}
}



/*** DecodingAudioPlayer.java ***/
[code=java]
[/code]][/code]
...全文
508 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
adfldk 2016-07-25
  • 打赏
  • 举报
回复
编解码不对吧 你代码是从别的地方弄来的么
likaixuan1986 2016-07-23
  • 打赏
  • 举报
回复
支持你下,想帮你但我是初学者看不懂你写的啥
Andy瑞波 2016-07-22
  • 打赏
  • 举报
回复
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED from MPEG1L3 44100.0 Hz, unknown bits per sample, stereo, unknown frame size, 38.28125 frames/second, at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:878) at com.mypro.basecomponet.DecodingAudioPlayer.main(DecodingAudioPlayer.java:81) 就是这样的错误!求救

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧