Android sound SoundPool: soundpool 1 not retry

Source: Internet
Author: User

Android sound SoundPool: soundpool 1 not retry

 


SoundPool is used in development today. When soundpool 1 not retry cannot play the sound, MediaPlay can

 


After some research, we found that:

Unable to play the sound because of the soundpool 1 not retry error code

Mgr = (AudioManager) MainActivity. this. getSystemService (Context. AUDIO_SERVICE );
// Initialize the soundPool object. The first parameter is the number of sound streams that can be played simultaneously. The second parameter is the sound type, and the third parameter is the sound quality.
SoundPool = new SoundPool (4, AudioManager. STREAM_MUSIC, 100 );
SoundPoolMap = new HashMap <Integer, Integer> ();
SoundPoolMap. put (1, soundPool. load (MainActivity. this, R. raw. or, 1 ));
SoundPoolMap. put (2, soundPool. load (MainActivity. this, R. raw. sd, 1 ));
Volume = mgr. getStreamVolume (AudioManager. STREAM_MUSIC );


// Loop: the loop mode in the loop (0 = No loop,-1 = infinite loop)
SoundPool. play (soundPoolMap. get (1), volume, volume, 1, 0, 1f );


Solution: the problem here is soundPool. load (MainActivity. this, R. raw. or, 1), that is, after loading () the audio file, play () immediately. The system has not prepared the sound file, so the problem has occurred.

Here you need to: load () in other places first, for example, load () in the constructor, and then call play () Where you need to play (), that is, it takes a while to call play ()

This is the case.

Mgr = (AudioManager) MainActivity. this. getSystemService (Context. AUDIO_SERVICE );
// Initialize the soundPool object. The first parameter is the number of sound streams that can be played simultaneously. The second parameter is the sound type, and the third parameter is the sound quality.
SoundPool = new SoundPool (4, AudioManager. STREAM_MUSIC, 100 );
SoundPoolMap = new HashMap <Integer, Integer> ();
SoundPoolMap. put (1, soundPool. load (MainActivity. this, R. raw. or, 1 ));
SoundPoolMap. put (2, soundPool. load (MainActivity. this, R. raw. sd, 1 ));
Volume = mgr. getStreamVolume (AudioManager. STREAM_MUSIC );
Try {
Thread. sleep (1000 );
} Catch (InterruptedException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
SoundPool. play (soundPoolMap. get (1), volume, volume, 1, 0, 1f );


 

Related Article

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.