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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

安卓使用SoundPool播放較短的聲音MP3(短信鈴聲)

2019-11-07 23:59:46
字體:
供稿:網(wǎng)友

效果

代碼

package com.javen.devicemange.CrazyOne.media;import android.media.AudioManager;import android.media.SoundPool;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import com.javen.devicemange.R;import java.util.HashMap;/** * Created by Administrator on 2017/2/24 0024. * 使用SoundPool播放較短的聲音MP3(短信鈴聲) * SoundPool使用音效池的概念來管理多個(gè)短暫聲音,支持多個(gè)聲音同時(shí)播放 */public class SoundPoolTest extends AppCompatActivity implements View.OnClickListener {    PRivate Button one;    private Button two;    HashMap<Integer, Integer> soundMap;    private SoundPool soundPool;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.soundpooltest);        initView();        soundMap = new HashMap<>();        //設(shè)置最多可以容納10個(gè)音頻流,音頻的品質(zhì)5        soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);        //load方法加載指定音頻文件,并返回所加載的音頻id        //使用HashMap來管理這些音頻流        int oneId = soundPool.load(this, R.raw.one_music, 1);        int twoId = soundPool.load(this, R.raw.two, 1);        soundMap.put(1, oneId);        soundMap.put(2, twoId);    }    private void initView() {        one = (Button) findViewById(R.id.one);        two = (Button) findViewById(R.id.two);        one.setOnClickListener(this);        two.setOnClickListener(this);    }    @Override    public void onClick(View v) {        switch (v.getId()) {            case R.id.one:                //播放one_music音樂                soundPool.play(soundMap.get(1), 1, 1, 0, 0, 1);                break;            case R.id.two:                //播放two音樂                soundPool.play(soundMap.get(2), 1, 1, 0, 0, 1);                break;        }    }}

raw目錄

布局xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:layout_width="match_parent"              android:layout_height="match_parent"              android:orientation="vertical">    <Button        android:id="@+id/one"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="播放音樂one"/>    <Button        android:id="@+id/two"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="播放音樂two"/></LinearLayout>

。。。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平果县| 酉阳| 新河县| 威海市| 阜阳市| 凯里市| 云龙县| 惠水县| 黔东| 右玉县| 鄂托克前旗| 云浮市| 广南县| 清苑县| 阿克苏市| 上林县| 莫力| 柳河县| 吉水县| 镇平县| 长海县| 舞阳县| 德清县| 婺源县| 富蕴县| 子洲县| 芜湖县| 黄平县| 泗水县| 易门县| 四平市| 敦煌市| 赣榆县| 罗山县| 原平市| 河东区| 应城市| 三江| 辽源市| 菏泽市| 诏安县|