AudioTrack Search in Android

Can someone help me how can I search for a sound song in a certain position, like in a media player, because my preference is to play a song using audiotrack not mediaplayer

Anyway, to search for a song using AudioTrack, please let me know? Thanks
You can see my song playback function using audiotrack, it works, but I can not search for it.

public void playDirect(){
    int i = 0;
    InputStream is = getResources().openRawResource(R.raw.output);
    int bufferSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
    Log.v("bufferSize", " "+ bufferSize);
    audioTrack =  new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM);
    byte[] music = new byte[512];

    try{
        audioTrack.play();
        audioTrack.setPlaybackPositionUpdateListener(this);

        while((i = is.read(music)) != -1){
            audioTrack.write(music, 0, i);
            Log.v(" audioTrack ", " audioTrack = "+ (( audioTrack.getPlaybackHeadPosition( ) / audioTrack.getSampleRate( ) ) * 1000.0));
            //Log.v(" audioTrack ", " audioTrack = "+ audioTrack.setLoopPoints(500, 2000, 6));
        }

        audioTrack.stop();
        audioTrack.release();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
+3
source share
1 answer

You cannot search with AudioTrack because you simply feed samples; AudioTrack knows nothing about the file or time.

, InputStream . - , 16 44100 , ,

bytesPerSecond = 44100 * 2 * 2; // 44100 samples, 2 channels, 2 bytes per sample

, , , 5 ,

seekPosition = 5 * bytesPerSecond; 
+2

All Articles