欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android利用SoundPool實(shí)現(xiàn)音樂(lè)池

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

本文實(shí)例為大家分享了Android利用SoundPool實(shí)現(xiàn)音樂(lè)池的具體代碼,供大家參考,具體內(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;
        }
    }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android使用插件實(shí)現(xiàn)代碼混淆

    Android使用插件實(shí)現(xiàn)代碼混淆

    這篇文章主要介紹了Android如何使用插件實(shí)現(xiàn)代碼混淆,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android仿淘寶商品瀏覽界面圖片滾動(dòng)效果

    Android仿淘寶商品瀏覽界面圖片滾動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android仿淘寶商品瀏覽界面圖片滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android列表動(dòng)圖展示的實(shí)現(xiàn)策略

    Android列表動(dòng)圖展示的實(shí)現(xiàn)策略

    這篇文章主要給大家介紹了關(guān)于Android列表動(dòng)圖展示的實(shí)現(xiàn)策略的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • 詳解flutter如何實(shí)現(xiàn)局部導(dǎo)航管理

    詳解flutter如何實(shí)現(xiàn)局部導(dǎo)航管理

    這篇文章主要為大家介紹了詳解flutter如何實(shí)現(xiàn)局部導(dǎo)航管理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • 讓Android中RadioGroup不顯示在輸入法上面的辦法

    讓Android中RadioGroup不顯示在輸入法上面的辦法

    在Android開(kāi)發(fā)中,發(fā)現(xiàn)一個(gè)問(wèn)題,打開(kāi)輸入法導(dǎo)致下面的radioGroup的位置發(fā)生了變化,被頂?shù)搅溯斎敕ǖ纳厦妫敲丛撊绾谓鉀Q呢?下面來(lái)看看。
    2016-08-08
  • Flutter仿釘釘考勤日歷的示例代碼

    Flutter仿釘釘考勤日歷的示例代碼

    這篇文章主要介紹了Flutter仿釘釘考勤日歷的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • 淺扒Android動(dòng)態(tài)設(shè)置字體大小的示例

    淺扒Android動(dòng)態(tài)設(shè)置字體大小的示例

    本篇文章主要介紹了淺扒Android動(dòng)態(tài)設(shè)置字體大小的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • 詳解Java編程中的反射在Android開(kāi)發(fā)中的應(yīng)用

    詳解Java編程中的反射在Android開(kāi)發(fā)中的應(yīng)用

    這篇文章主要介紹了詳解Java編程中的反射在Android開(kāi)發(fā)中的應(yīng)用,主要來(lái)獲取安卓系統(tǒng)的屬性值,需要的朋友可以參考下
    2015-07-07
  • 詳解Android中實(shí)現(xiàn)Redux方法

    詳解Android中實(shí)現(xiàn)Redux方法

    本篇文章給大家通過(guò)代碼實(shí)例教學(xué)Android中實(shí)現(xiàn)Redux的方法,有需要的朋友跟著參考下吧。
    2018-01-01
  • Android?OkHttp庫(kù)簡(jiǎn)單使用和封裝教程助你快速掌握網(wǎng)絡(luò)請(qǐng)求技能

    Android?OkHttp庫(kù)簡(jiǎn)單使用和封裝教程助你快速掌握網(wǎng)絡(luò)請(qǐng)求技能

    OkHttp是一個(gè)高效的HTTP客戶端庫(kù),適用于Android和Java應(yīng)用程序。它支持HTTP/2和SPDY協(xié)議,提供了同步和異步請(qǐng)求API、請(qǐng)求和響應(yīng)攔截器、連接池和多路復(fù)用器、緩存支持、GZIP和DEFLATE壓縮等功能,可以大大提高網(wǎng)絡(luò)請(qǐng)求的性能和可擴(kuò)展性
    2023-04-04

最新評(píng)論