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

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

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

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

運(yùn)行效果圖如下:

布局文件(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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

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

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

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

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

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

    Android OpenGLES如何給相機(jī)添加濾鏡詳解

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

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

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

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

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

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

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

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

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

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

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

    Android日期選擇控件使用詳解

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

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

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

最新評論

桐庐县| 盐山县| 黎平县| 武平县| 香格里拉县| 凌海市| 珲春市| 靖西县| 安岳县| 乌苏市| 石家庄市| 榆树市| 金山区| 阿合奇县| 保定市| 海晏县| 赤水市| 安义县| 固阳县| 大英县| 柘城县| 宜兰市| 麟游县| 永城市| 新闻| 高唐县| 陈巴尔虎旗| 丰台区| 万盛区| 莆田市| 沾益县| 明水县| 团风县| 中西区| 长岭县| 东安县| 桐梓县| 类乌齐县| 武陟县| 长宁县| 石棉县|