Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use SoundPool to realize Music Pool in Android

Shulou Source: shulou.com Published: 2022-06-02 15:30:13 11月10日 Update

This article mainly introduces how Android uses SoundPool to achieve music pool, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

This paper gives you an example to share the specific code of Android using SoundPool to realize music pool for your reference. The details are as follows.

The running effect is as follows:

Layout file (activity_sound_pool.xml)

Java code

Package com.example.g150825_android26;import android.app.AlarmManager;import android.media.AudioManager;import android.media.SoundPool;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class SoundPoolActivity extends AppCompatActivity {private SoundPool soundPool; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_sound_pool); soundPool = new SoundPool (4, AudioManager.STREAM_MUSIC,0) SoundPool.setOnLoadCompleteListener (new SoundPool.OnLoadCompleteListener () {@ Override public void onLoadComplete (SoundPool soundPool, int I, int i1) {soundPool.play } public void playTWO (View view) {soundPool.load (this,R.raw.chimp,1);} public void playThree (View view) {soundPool.load (this,R.raw.crickets,1);} public void playFour (View view) {soundPool.load (this,R.raw.roar,1);} public void playDog (View view) {soundPool.load (this,R.raw.dogbark,1) } @ Override protected void onDestroy () {super.onDestroy (); if (soundPoolbasket null) {soundPool.release (); soundPool=null Thank you for reading this article carefully. I hope the article "Android how to use SoundPool to realize Music Pool" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles music code reference value interest content at the same time examples layout effects rendering documents more friends knowledge editing industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information vpn NVidia Huawei