Precautions for calling the pause stop method in Android soundpool

Source: Internet
Author: User

I believe Android uses soundpool.

The advantages of Android soundpool are not mentioned.

What I want to talk about now is

During initialization:

@Override    protected void onStart() {        mPoolTurnSignal = new SoundPool(1, AudioManager.STREAM_SYSTEM, 100);          turnSignal = mPoolTurnSignal.load(this, R.raw.turn_signal, 0);}    protected void onResume() {                mPoolTurnSignal = new SoundPool(1, AudioManager.STREAM_SYSTEM, 100);          turnSignal = mPoolTurnSignal.load(this, R.raw.turn_signal, 0);}private void SetForSingalSound() {        if(mSingView.getProtocolLampSignal() != 0 )        {            if(PoolState == POOL_PRESTART)            {                mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7);                PoolState = POOL_PLAYING;            }        }        else        {            if(PoolState == POOL_PLAYING)            {                mPoolTurnSignal.pause(turnSignal);                PoolState = POOL_PRESTART;            }                }    }

After play

Pause and stop
Once it is enabled, it cannot be closed.
Depressed for a whole day
Now the problem is found.

private void SetForSingalSound() {        if(mSingView.getProtocolLampSignal() != 0 )        {            if(PoolState == POOL_PRESTART)            {int tt = mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7);Log.i("MicroCar:", "SetForSingalSound tt "+tt);                PoolState = POOL_PLAYING;            }        }        else        {            if(PoolState == POOL_PLAYING)            {                mPoolTurnSignal.pause(turnSignal);                PoolState = POOL_PRESTART;            }                }    }

Note that after the red font is changed
You can see logcat.
It turns out that the returned value for each play is changed.
Through logcat, we can see that each time TT is opened, different values are 1, 2, 3, 4, 5, and 6 ....
However, what I disabled or paused before is

Mpoolturnsignal. Pause (turnsignal );

Turnsignal is the first value of initialization, and the value after the second open is different, so it is necessary to pass the response value to close
For example

turnSignal = mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7);Log.i("MicroCar:", "SetForSingalSound turnSignal:"+turnSignal);mPoolTurnSignal.pause(turnSignal);

It should be okay now.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.