@Override
protected Void doInBackground(Void... arg0) {
isPlaying = true;
int bufferSize = AudioTrack.getMinBufferSize(frequence, channelConfig, audioEncoding);
byte[] buffer = new byte[bufferSize/4];
try {
InputStream is = getResources().openRawResource(R.raw.temp);
//定义输入流,将音频写入到AudioTrack类中,实现播放
DataInputStream dis = new DataInputStream(new BufferedInputStream(is));
//实例AudioTrack
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC,
frequence,
channelConfig,
audioEncoding,
bufferSize,
AudioTrack.MODE_STREAM);
//开始播放
track.setStereoVolume(1.0f, 1.0f);
track.play
java 层 用 AudioTrack 播放 pcm 格式的音频文件
最新推荐文章于 2024-06-22 14:08:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)