最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android利用SoundPool實現(xiàn)音樂池

 更新時間:2021年11月14日 15:46:46   作者:安之若素i  
這篇文章主要為大家詳細介紹了Android利用SoundPool實現(xiàn)音樂池,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android利用SoundPool實現(xiàn)音樂池的具體代碼,供大家參考,具體內(nèi)容如下

運行效果圖如下:

布局文件(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;
        }
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中檢查、監(jiān)聽電量和充電狀態(tài)的方法

    Android中檢查、監(jiān)聽電量和充電狀態(tài)的方法

    這篇文章主要介紹了Android中檢查、監(jiān)聽電量和充電狀態(tài)的方法,如判斷當前充電狀態(tài)、監(jiān)聽充電狀態(tài)的改變、判斷當前剩余電量等,需要的朋友可以參考下
    2014-06-06
  • Android開發(fā)中的錯誤及解決辦法總結(jié)

    Android開發(fā)中的錯誤及解決辦法總結(jié)

    本文屬于個人平時項目開發(fā)過程遇到的一些問題,記錄下來并總結(jié)解決方案,希望能幫到大家解決問題,需要的朋友可以參考下
    2022-02-02
  • Android OpenGLES如何給相機添加濾鏡詳解

    Android OpenGLES如何給相機添加濾鏡詳解

    這篇文章主要給大家介紹了關(guān)于Android OpenGLES如何給相機添加濾鏡的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-08-08
  • Android RecyclerView打造懸浮效果的實現(xiàn)代碼

    Android RecyclerView打造懸浮效果的實現(xiàn)代碼

    本篇文章主要介紹了Android RecyclerView打造懸浮效果的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android控件Spinner的使用方法(1)

    Android控件Spinner的使用方法(1)

    這篇文章主要為大家詳細介紹了Android控件Spinner的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Flutter數(shù)據(jù)庫的使用方法

    Flutter數(shù)據(jù)庫的使用方法

    這篇文章主要介紹了Flutter數(shù)據(jù)庫的使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • Android 實現(xiàn)自定義圓形listview功能的實例代碼

    Android 實現(xiàn)自定義圓形listview功能的實例代碼

    這篇文章主要介紹了Android 實現(xiàn)自定義圓形listview功能的實例代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • Android實現(xiàn)通話最小化懸浮框效果

    Android實現(xiàn)通話最小化懸浮框效果

    本片內(nèi)容給大家介紹了Android音視頻通話過程中最小化成懸浮框的實現(xiàn)的方法以及代碼寫法。
    2017-11-11
  • Android日期選擇控件使用詳解

    Android日期選擇控件使用詳解

    這篇文章主要為大家詳細介紹了Android日期選擇控件的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android實現(xiàn)京東App分類頁面效果

    Android實現(xiàn)京東App分類頁面效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)京東App分類頁面效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02

最新評論

屏东县| 通江县| 馆陶县| 临高县| 宜阳县| 镇宁| 山东省| 晋江市| 时尚| 托克逊县| 周口市| 阿城市| 大埔县| 达日县| 蓬莱市| 兴海县| 双鸭山市| 全州县| 甘德县| 松阳县| 汝城县| 万源市| 米脂县| 称多县| 仁怀市| 云南省| 苍溪县| 蕉岭县| 柏乡县| 化隆| 长武县| 临夏市| 华宁县| 会昌县| 兴隆县| 大化| 永川市| 桐柏县| 东丽区| 瓮安县| 汉川市|