开发者

OGG Audio to AudioTrack

I'm trying to load an OGG file onto an AudioTrack so that I can manage the playback rate and play it. However, I'm getting a null pointer exception at the line "track[voiceIndex] = dis.readByte();". I suppose it's going out of bounds of the track array. I honestly don't know much about data streams so I just kinda copied this code. I'm having a hard time understanding it. Any help would be appreciated, thanks.

开发者_运维问答.....
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();


You can use MediaExtractor to obtain audio data: link, but it's available from API level 16. In erlier versions you can use one of external libraries to decode audio.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜