600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > android打开wav格式 在Android中使用AudioTrack播放WAV文件

android打开wav格式 在Android中使用AudioTrack播放WAV文件

时间:2020-08-04 05:52:39

相关推荐

android打开wav格式 在Android中使用AudioTrack播放WAV文件

我偶然发现了这个答案(坦白说,通过尝试& ^ @!我没有想到会工作),如果有人有兴趣…在我的原始代码(这是源自原始帖子中的链接的例子) ,数据从文件中读取如下:

InputStream is = new FileInputStream (file);

BufferedInputStream bis = new BufferedInputStream (is, 8000);

DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file

int i = 0; // Read the file into the "music" array

while (dis.available() > 0)

{

music[i] = dis.readShort(); // This assignment does not reverse the order

i++;

}

dis.close(); // Close the input stream

在这个版本中,音乐[]是SHORTS的数组。所以,readShort()方法似乎在这里是有意义的,因为数据是16位PCM …但是,在Android上似乎是问题。我将该代码更改为以下内容:

music=new byte[(int) file.length()];//size & length of the file

InputStream is = new FileInputStream (file);

BufferedInputStream bis = new BufferedInputStream (is, 8000);

DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file

int i = 0; // Read the file into the "music" array

while (dis.available() > 0)

{

music[i] = dis.readByte(); // This assignment does not reverse the order

i++;

}

dis.close(); // Close the input stream

在这个版本中,音乐[]是一系列BYTES。我仍然在告诉AudioTrack它是16位PCM数据,而我的Android似乎没有写入一个字节数组到一个AudioTrack这样配置的问题…无论如何,最后听起来对,所以如果有人否则想要在Android上播放Windows声音,由于某种原因,这就是解决方案。啊,结尾……

R.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。