感谢您的回答麦克。但不幸的是,这不会帮助我。
假设我让MediaPlayer在00:00开始播放长度为3:45的歌曲。
01:00我开始使用手机的资源,由于我的手机用量过大,使MediaPlayer暂停2秒。
时间:
00:00-01:00 -我听到了声音,在00:00-01:00
01:00-01:02 -我听到沉默,因为手机glitched
01:02-03:47 -我听到01的声音:00-03:45和2秒的时间偏移
现在从我的理解MediaPlayer正在使用的对这个问题领域一个不错的选择,因为MediaPlayer
提供高级API。
我目前与 AudioTrack
类实验应该提供给我什么,我需要:
//Creating a new audio track
AudioTrack audioTrack = new AudioTrack(...)
//Get start time
long start = System.currentTimeMillis();
// loop until finished
for (...) {
// Get time in song
long now = System.currentTimeMillis();
long nowInSong = now - start;
// get a buffer from the song at time nowInSong with a length of 1 second
byte[] b = getAudioBuffer(nowInSong);
// play 1 second of music
audioTrack.write(b, 0, b.length);
// remove any unplayed data
audioTrack.flush();
}
现在,如果我毛刺我唯一问题1秒钟,然后我通过打右音频在正确的时间纠正自己!
注意
我没有测试代码,但它似乎是做了正确的方式。如果它真的有效,我会再次更新这篇文章。
P.S.MediaPlayer
的搜索结果如下: 1.一个沉重的操作,肯定会延迟我的音乐(每毫秒数在这里) 2.不是线程安全的,不能用于多线程(寻求,启动等...)