Android soundpool parameter description, androidsoundpool

Source: Internet
Author: User

Android soundpool parameter description, androidsoundpool

The SoundPool class constructor is as follows:

SoundPool (int maxStreams, int streamType, int srcQuality)

Purpose: instantiate a SoundPool instance.

First parameter: maximum value of sound that can be played simultaneously

Second parameter: Sound type

Third parameter: Sound Quality

Common functions of the SoundPool class are as follows:

Int load (Context context, int resId, int priority)

Purpose: load the music file and return the music ID (music stream file data)

First parameter: Context instance

The second parameter is the music file Id.

The third parameter indicates the sound with priority. Currently, it has no effect, but has the compatibility value.

Int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, floatrate)

Purpose: Play the music. If the playback fails, 0 is returned. If the playing fails, a non-0 value is returned for normal playback.

The first parameter is the ID of the uploaded music file.

The second parameter indicates the left audio channel of the volume. The value range is 0.0 ~ 1.0

Third parameter: right channel of the volume, range: 0.0 ~ 1.0

Fourth parameter: the priority of the music stream. 0 is the lowest priority.

Fifth parameter: the number of times the music is played.-1 indicates an infinite loop, 0 indicates a normal one, and greater than 0 indicates the number of cycles.

Sixth parameter: playback speed. value range: 0.5 ~ 2.0, 1.0 indicates normal playback

Pause (int streamID)

Purpose: pause music playback.

Parameter: The Stream ID after the music file is loaded.

Stop (int streamID)

Purpose: end music playback.

Parameter: The Stream ID after the music file is loaded.

Release ()

Purpose: Release SoundPool Resources

SetLoop (int streamID, int loop)

Purpose: set the number of cycles.

The first parameter is the stream ID after the music file is loaded.

Second parameter: number of cycles

SetRate (int streamID, float rate)

Purpose: set the playback rate.

The first parameter is the stream ID after the music file is loaded.

Second parameter: rate value

SetVolume (int streamID, float leftVolume, float rightVolume)

Purpose: set the volume.

The first parameter is the stream ID after the music file is loaded.

Second parameter: Left-channel volume

Third parameter: Right-channel volume

SetPriority (int streamID, int priority)

Purpose: set the stream priority.

The first parameter is the stream ID after the music file is loaded.

Second parameter: Priority Value


Android MediaPlayer and SoundPool usage Problems

There are two ways to play audio on the Android platform:
1. SoundPool-suitable for scenarios with short promotion and high response speed (game sound effects or button sounds)
2. MediaPlayer-suitable for long and time-demanding scenarios
Bytes -------------------------------------------------------------------------------------------
SoundPool
1. Create a SoundPool
Public SoundPool (int maxStream, int streamType, int srcQuality)
MaxStream -- maximum number of streams simultaneously played
StreamType -- stream type, which is generally STREAM_MUSIC (listed in the AudioManager class)
SrcQuality -- sampling rate conversion quality. No effect currently. Use 0 as the default value.
Eg.
SoundPool soundPool = new SoundPool (3, AudioManager. STREAM_MUSIC, 0 );
Creates a SoundPool that supports simultaneous playback of up to three streams and marks the type as music.
2. Load audio Resources
One audio resource can be recorded in four ways:
Int load (AssetFileDescriptor afd, int priority)
Use an AssetFileDescriptor object
Int load (Context context, int resId, int priority)
Use a resource ID
Int load (String path, int priority)
Load through the specified path
Int load (FileDescriptor fd, long offset, long length, int priority)
Load with FileDescriptor
* The API indicates that the priority parameter has no effect currently. We recommend that you set it to 1.
A single SoundPool can manage multiple audios at the same time, so you can call the load function multiple times to record the results. If the recording succeeds, a non-zero soundID is returned, which is used to specify a specific audio during playback.
Eg.
Int soundID1 = soundPool. load (this, R. raw. sound1, 1 );
If (soundID1 = 0 ){
// Recording failed
} Else {
// Load successful
}
Int soundID2 = soundPool. load (this, R. raw. sound2, 1 );
...
Two streams are loaded and the returned soundID is recorded respectively.
Note that,
The stream loading process is a process of extracting audio into the original 16-bit PCM data, and a background thread is used for asynchronous processing. Therefore, it cannot be played immediately after initialization. It takes some time to wait.
3. Playback Control
You can use the following functions to control playback:
Final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)
Play the sound of the specified audio and return a streamID.
Priority-stream priority. A higher value has a higher priority, which affects the processing of the stream when the number of simultaneous playback exceeds the maximum supported number;
Lo ...... remaining full text>
 
Soundpool problems in android

It's too long .. Have time to study .. Now do the task.
 

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.