public class AudioInputStream extends InputStream
AudioSystem类包含许多操纵AudioInputStream对象的方法。 例如,方法让你:
AudioSystem , Clip.open(AudioInputStream)
| Modifier and Type | Field and Description |
|---|---|
protected AudioFormat |
format
流中包含的音频数据的格式。
|
protected long |
frameLength
这个流的长度,采样帧。
|
protected long |
framePos
这个流中的当前位置,在采样帧中(从零开始)。
|
protected int |
frameSize
每个帧的大小,以字节为单位。
|
| Constructor and Description |
|---|
AudioInputStream(InputStream stream, AudioFormat format, long length)
使用来自指定输入流的音频数据构建音频输入流,该音频输入流在采样帧中具有请求的格式和长度。
|
AudioInputStream(TargetDataLine line)
构建从所指示的目标数据线读取其数据的音频输入流。
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
返回从该音频输入流中可以读取(或跳过)的最大字节数,而不会阻塞。
|
void |
close()
关闭此音频输入流并释放与流相关联的任何系统资源。
|
AudioFormat |
getFormat()
获取此音频输入流中声音数据的音频格式。
|
long |
getFrameLength()
获取流的长度,以采样帧而不是字节表示。
|
void |
mark(int readlimit)
标记此音频输入流中的当前位置。
|
boolean |
markSupported()
测试此音频输入流是否支持
mark和
reset方法。
|
int |
read()
从音频输入流读取数据的下一个字节。
|
int |
read(byte[] b)
从音频输入流读取一些字节数,并将它们存储到缓冲器阵列
b 。
|
int |
read(byte[] b, int off, int len)
从音频流读取指定的最大数据字节数,将它们放入给定的字节数组。
|
void |
reset()
将此音频输入流重新定位到上次调用其
mark方法时的位置。
|
long |
skip(long n)
跳过并丢弃该音频输入流中指定数量的字节。
|
protected AudioFormat format
protected long frameLength
protected int frameSize
protected long framePos
public AudioInputStream(InputStream stream, AudioFormat format, long length)
stream - 此
AudioInputStream对象所基于的流
format - 此流的音频数据的格式
length - 此流中数据的样本帧中的长度
public AudioInputStream(TargetDataLine line)
line - 此流获取其数据的目标数据行。
AudioSystem.NOT_SPECIFIED
public AudioFormat getFormat()
public long getFrameLength()
public int read()
throws IOException
IOException 。
read在类别
InputStream
IOException - 如果发生输入或输出错误
read(byte[], int, int) , read(byte[]) ,
public int read(byte[] b)
throws IOException
b 。
实际读取的字节数作为整数返回。
该方法阻塞直到输入数据可用,检测到流的结尾,或抛出异常。
该方法将始终读取整数个帧。 如果阵列的长度不是整数帧,则最多可读取b.length - (b.length % frameSize)字节。
read在类别
InputStream
b - 读取数据的缓冲区
IOException - 如果输入或输出错误发生
read(byte[], int, int) ,
read() ,
available()
public int read(byte[] b,
int off,
int len)
throws IOException
该方法将始终读取整数个帧。 如果len未指定整数帧,则最多可读取len - (len % frameSize)字节。
read在类别
InputStream
b - 读取数据的缓冲区
off - 从数组
b的偏移量,数据将写入数组
b
len - 要读取的最大字节数
IOException - 如果发生输入或输出错误
read(byte[]) ,
read() ,
skip(long) ,
available()
public long skip(long n)
throws IOException
skip在类别
InputStream
n - 要跳过的请求的字节数
IOException - 如果发生输入或输出错误
read() ,
available()
public int available()
throws IOException
read或skip方法;
每次调用这些方法时,限制可能会有所不同。
根据底层流,如果此流已关闭,则可能会抛出IOException。
available在类别
InputStream
IOException - 如果发生输入或输出错误
read(byte[], int, int) ,
read(byte[]) ,
read() ,
skip(long)
public void close()
throws IOException
close在界面
Closeable
close在界面
AutoCloseable
close在类
InputStream
IOException - 如果发生输入或输出错误
public void mark(int readlimit)
mark在类别
InputStream
readlimit - 标记位置无效之前可以读取的最大字节数。
reset() ,
markSupported()
public void reset()
throws IOException
mark方法时的位置。
reset在类别
InputStream
IOException - 如果发生输入或输出错误。
mark(int) ,
markSupported()
public boolean markSupported()
mark和
reset方法。
markSupported在类别
InputStream
true如果这个流支持mark和reset方法;
false否则
mark(int) ,
reset()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.