了解 AudioFormat 、 AudioInputStream 的构造函数和 start 方法
我曾尝试编写播放声音文件的程序,但到目前为止尚未成功。 我无法理解代码的某些部分:
InputStream is = new FileInputStream("sound file");
AudioFormat af = new AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian); // I don't understand it's constructor
long length ; // length in sample frames
// how cani i know the length of frames ?
AudioInputStream ais = new AudioInputStream( is , af , length );
// open ( ais );
// start playing by invoking start method
- 在
AudioFormat
的构造函数中,我如何提前知道采样率、文件大小、通道是什么以及最后的 2 个布尔变量? - 如何获取样本帧的值(
length
)? - 另外我如何调用start方法?我不希望来自任何行的数据,而是来自保存在文件夹中的文件(即剪辑)
I have tried writing program that plays a sound file but have been unsuccessful so far.
I am unable to understand some parts of the code:
InputStream is = new FileInputStream("sound file");
AudioFormat af = new AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian); // I don't understand it's constructor
long length ; // length in sample frames
// how cani i know the length of frames ?
AudioInputStream ais = new AudioInputStream( is , af , length );
// open ( ais );
// start playing by invoking start method
- In the constructor of
AudioFormat
how can I know the sample rate, file size in advance, what are channels, and the 2 boolean variable in the end? - How can I get the value of sample frames (
length
)? - Also how do I invoke start method? I don't want the data from any line but from the file kept in a folder (i.e a clip)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接
Link
解决此问题的更好方法可能是沿着 中显示的“播放
Clip
”源代码。 Java 声音信息。 页面。它使大多数问题变得多余(因为我们在使用Clip
时不需要担心细节)。如果您在尝试来源后还有任何其他问题,请告诉我。
Probably a better way to approach this is along the lines of the 'Playing a
Clip
' source code shown in the Java Sound info. page. It makes most of the questions redundant (since we don't need to worry about the fine details when using aClip
).If you have any further questions after trying the source, let me know.