Code example for AudioTrack

Methods: getStateplayreleasewrite

0
 
    private void create(String path) {//НЕ РАБОТАЕТ
        try { 
            Debug.trace(" player, path:" + path);
            if (data == null) return;
            player = new AudioTrack(AudioManager.STREAM_MUSIC, 48000, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT /*CHANNEL_OUT_DEFAULT api > 8*/, AudioFormat.ENCODING_PCM_16BIT, data.length(), AudioTrack.MODE_STREAM);
            player.write(data.getArray(), 0, data.length());
            filename = path;
            isPlayed = false;
 
            player.release();
            Debug.trace("Prepared." + toString()); 
            play(); 
        } catch (IllegalArgumentException e) {
            Debug.trace(e.toString() + " " + toString());
        } catch (Exception e) {
            Debug.logEx(e);
        } 
    } 
 
    public void play() { 
        if (player == null) return;
        try { 
            if (player.getState() != AudioTrack.STATE_INITIALIZED) return;
            player.play();
        } catch (IllegalStateException e) {
            log(e.toString() + " " + toString());
        } 
        //log("SoundPlayer.play, name:" + filename + ", state:" + getState()); 
    }