Android 声音池-声音文件中的哪个位置

Android 声音池-声音文件中的哪个位置,android,soundpool,Android,Soundpool,我在Android中使用Soundpool加载了声音 我使用了play功能来播放声音 在播放文件时,如何知道文件的长度以及我当前在该文件中的位置?声音文件持续时间 这可能是你最好的选择,这里: MediaPlayer player = MediaPlayer.create(ctxt, R.raw.mysound); int duration = player.getDuration(); player.release(); //(If not using this player later

我在Android中使用Soundpool加载了声音

我使用了
play
功能来播放声音


在播放文件时,如何知道文件的长度以及我当前在该文件中的位置?

声音文件持续时间

这可能是你最好的选择,这里:

MediaPlayer player = MediaPlayer.create(ctxt, R.raw.mysound);
int duration = player.getDuration();
player.release();    //(If not using this player later on)
当前播放位置

SoundPool
不支持此功能。您的三个主要选择:

  • 使用
    MediaPlayer
    播放
    MediaPlayer
    提供了一个
    getCurrentPosition()
    方法
  • 使用--以字节为单位手动将未压缩的音频发送到流
    AudioTrack
    具有一些确定播放位置的基本功能(在大多数设备上,通常精确到几十毫秒以内),此外,您还可以准确地知道有多少音频添加到播放缓冲区
  • 坚持使用
    声音池
    ,但自己计时播放。也就是说,花一点时间破解()或设置一个,并通过假设播放在
    play()
    返回时就开始来估计播放位置。这种方法充满了问题和不准确之处,但其好处是不涉及音轨的复杂性