国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 利用SoundPool實現音樂池

2019-11-08 00:24:03
字體:
來源:轉載
供稿:網友

運行效果圖如下:

這里寫圖片描述這里寫圖片描述

布局文件(activity_sound_pool.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_sound_pool" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.example.g150825_android26.SoundPoolActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="音效雞" android:onClick="playKFC" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="音效TWO" android:onClick="playTWO" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="音效Three" android:onClick="playThree" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="音效Four" android:onClick="playFour" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="音效狗" android:onClick="playDog" /></LinearLayout>

java 代碼

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(i,1,1,1,-1,1); } }); } public void playKFC(View view){ soundPool.load(this,R.raw.rooster,1); } 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 (soundPool!=null){ soundPool.release(); soundPool=null; } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福清市| 临沂市| 平原县| 敦煌市| 靖边县| 赞皇县| 隆尧县| 武功县| 巍山| 上犹县| 包头市| 申扎县| 科尔| 乌什县| 宁夏| 桑日县| 武定县| 通许县| 许昌县| 北流市| 怀远县| 朝阳县| 马龙县| 交城县| 石林| 扎赉特旗| 苏州市| 西林县| 城固县| 子洲县| 邵阳县| 桂阳县| 万源市| 九龙县| 荆门市| 宁国市| 保靖县| 莎车县| 宝应县| 南澳县| 安阳市|