java 소리 재생 AudioStream.getData()이상
최근 에 작은 애플 리 케 이 션 을 쓰 고 자바 가 소 리 를 재생 하 는 라 이브 러 리 를 사 용 했 습 니 다.인터넷 에 많은 예 가 있어 서 하 나 를 찾 았 습 니 다.
code from http://dracularking.iteye.com/blog/738917
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import sun.audio.ContinuousAudioDataStream;
public class MusicPlay {
private AudioStream as; //
ContinuousAudioDataStream cas;//
//
public MusicPlay(URL url) {
try {
//
as = new AudioStream(url.openStream());
} catch(FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
public void start() {
if(as == null) {
System.out.println("AudioStream object is not created!");
return;
} else {
AudioPlayer.player.start(as);
}
}
//
public void stop() {
if(as == null) {
System.out.println("AudioStream object is not created!");
return;
} else {
AudioPlayer.player.stop(as);
}
}
//
public void continuousStart() {
// Create AudioData source.
AudioData data = null;
try {
data = as.getData();
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Create ContinuousAudioDataStream.
cas = new ContinuousAudioDataStream(data);
// Play audio.
AudioPlayer.player.start(cas);
}
//
public void continuousStop() {
if(cas != null) {
AudioPlayer.player.stop(cas);
}
}
}
불 행 히 도 사용 중 순환 재생 을 사용 할 때 Continuous AudioDataStream 클래스 를 만 들 때 data=as.getData()라 는 문장 에 이상 java.io.IOException:could not create AudioData object 가 나 타 났 습 니 다.
인터넷 에서 많은 자 료 를 찾 아 보 았 지만 해결 되 지 않 았 습 니 다.오디 오 파일 형식 이 틀 렸 다 고 합 니 다.라 이브 러 리 에 문제 가 있다 고 합 니 다.그런데 해결 되 지 않 았 습 니 다.나중에 AudioStream 류 소스 파일 의 getData 함 수 를 살 펴 본 결과 getData()는 오디 오 파일 의 길이 에 제한 이 있 고 1M 를 초과 할 수 없 으 며 원인 을 찾 았 습 니 다.Nd 라 는 원인 으로 인 한 이상 은 정말 비극 적 입 니 다.인터넷 에서 이런 상황 을 전혀 찾 을 수 없어 요.자바 독 에서 도 설명 이 없어 요...
http://www.docjar.com/html/api/sun/audio/AudioStream.java.html
102 public AudioData getData() throws IOException {
103 int length = getLength();
104
105 //limit the memory to 1M, so too large au file won't load
106 if (length < 1024*1024) {
107 byte [] buffer = new byte[length];
108 try {
109 ais.read(buffer, 0, length);
110 } catch (IOException ex) {
111 throw new IOException("Could not create AudioData Object");
112 }
113 return new AudioData(format, buffer);
114 }
115
116 /* acis.setData();
117
118 if (acis.stream instanceof ByteArrayInputStream) {
119 Format[] format = acis.getFormat();
120 byte[] bytes = acis.getBytes();
121 if (bytes == null)
122 throw new IOException("could not create AudioData object: no data received");
123 return new AudioData((AudioFormat)format[0], bytes);
124 }
125 */
126
127 throw new IOException("could not create AudioData object");
128 }
또한 소 리 를 재생 하 는 코드 에 문제 가 있 으 므 로 링크 를 참고 해 야 합 니 다.http://www.java2s.com/Code/JavaAPI/sun.audio/newAudioStreamInputStreamarg0.htm
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.