Hi,
I tried using SoundPool for a new audio-application.
For Example, I made a Button: when it is pressed the sound should
play, otherwise it should stop playing. But  sometimes it takes more
than 300 ms until the sound stops!
That's too long for my application-requirements.

For checking the causes of this behavior, I made the play and stop-
call directly in sequence, without the Button Down and Up-Requirement.
The result is: The time before the play-call until after the stop-call
is typically 100 ms.
But independently of this time I heard the sound longer than 300 ms!
This happens approx. 10 % the time, in the other cases I heard nothing
or only very short sounddetails.

The Eclipse-LogCat shows some serious messages:
...
AudioTrack   Error obtaining an audio buffer, giving up.
...
AudioFlinger write blocked for 53 msecs
...
Once:
AudioTrack   setLoop invalid value: loopStart 0, loopEnd 33469,
loopCount 99, framecount 0, user 0
(by the way: I am not able to cut and paste the contents from the
Eclipse-LogCat-View, how to do this?)

These are all experiences with my Android-Emulator, not with a real
device.
The running Hardware:
Pentium(R) 4 CPU 2.60GHz, 512 MB RAM
Software:
Microsoft Windows XP, Home Edition, Version 2002, Service Pack 3
Eclipse Platform:
Version: 3.3.2
Android 1.5 SDK

Please give me a feedback.

Greetings from Germany

Ulrich Althöfer


My Java-Source of the file SoundT1.java:

package de.spec_i.SoundT1;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

public class SoundT1 extends Activity {
    /** Called when the activity is first created. */
    public int soundID;
    public int streamID;
    public long tmp1;
    public long tmp2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final SoundPool mySP = new SoundPool(1, 0x00000003, 0); //
neue Instanz der Klasse SoundPool
        // Hinweis: insgesamt darf der SoundPool wohl nicht über 100
kB groß sein!
        // Die Sounddateien sind im raw-Verzeichnis mit der '.wav'-
extension angelegt:
        AssetFileDescriptor tmpAFD;
        tmpAFD = getResources().openRawResourceFd(R.raw.sample6); //
ohne Extension ansprechen
        soundID = mySP.load(tmpAFD,1);                  // Load Sample
        Log.d("SoundT1", "load sample, soundID: " + soundID);

        final Button button1 = (Button) findViewById(R.id.Button01);
        // Button1
        button1.setOnTouchListener(new View.OnTouchListener() {
                public boolean  onTouch(View v, MotionEvent e) {
                        if (e.getAction() == MotionEvent.ACTION_DOWN) {
                                // final int play(int soundID, float 
leftVolume, float
rightVolume,
                                // int priority, int loop, float rate):
                                streamID = mySP.play(soundID, 1, 1, 0, 99, 1);
                                if (streamID == 0) {                    // 0: 
not READY
                                        Log.d("SoundT1", "after play1, play not 
ready!");
                                }
                        }
                        if (e.getAction() == MotionEvent.ACTION_UP) {
                        mySP.stop(streamID);                    // Stop Loop 
mit vorher
gemerkter streamID.
                        }
                        return true;
                }
        });     // Button new Ende

        final Button button2 = (Button) findViewById(R.id.Button02);
        // Button2
        button2.setOnTouchListener(new View.OnTouchListener() {
                public boolean  onTouch(View v, MotionEvent e) {
                        if (e.getAction() == MotionEvent.ACTION_DOWN) {
                                tmp1 = System.currentTimeMillis();
                                streamID = mySP.play(soundID, 1, 1, 0, 99, 1);
                                if (streamID == 0) {                    // 0: 
not READY
                                        Log.d("SoundT1", "after play2, play not 
ready!");
                                }
                                mySP.stop(streamID);
                                tmp2 = System.currentTimeMillis();
                        Log.d("SoundT1", "Time before play-call and after
stop-call: " + (tmp2 - tmp1) + "ms");
                        }
                        return true;
                }
        });     // Button new Ende

    }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to