我正在尝试将OGG文件加载到AudioTrack上,以便我可以管理播放速率并播放它。但是,我在“track [voiceIndex] = dis.readByte();”行中得到一个空指针异常。我想它超出了轨道阵列的范围。老实说,我对数据流知之甚少,所以我只是复制了这段代码。我很难理解它。任何帮助将不胜感激,谢谢。
.....
private AudioTrack voice = null;
private InputStream is = null;
private byte[] track = null;
private BufferedInputStream bis = null;
private DataInputStream dis = null;
.......
int playbackRate = 0;
is = getResources().openRawResource(sentences[index].voice);
bis = new BufferedInputStream(is, 8000);
dis = new DataInputStream(bis);
while (dis.available() > 0){
track[voiceIndex] = dis.readByte();
voiceIndex++;
}
voice.write(track, 0, track.length);
playbackRate = voice.getPlaybackRate();
voice.play();