Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SoundPool to realize Music Pool in Android

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report