• soundpool简介


    package com.itheima.soundpool;

    import android.app.Activity;

    import android.media.AudioManager;

    import android.media.SoundPool;

    import android.os.Bundle;

    import android.view.View;

    public class MainActivity extends Activity {

     private SoundPool soundPool;

     private int soundId;

     @Override

     protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

      /**

       * maxStreams<br>

       * the maximum number of simultaneous streams for this SoundPool object<br>

       * streamType<br>

       * the audio stream type as described in AudioManager For example, game

       * applications will normally use STREAM_MUSIC.<br>

       * srcQuality<br>

       * the sample-rate converter quality. Currently has no effect. Use 0 for

       * the default.

       */

      soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

      /**

       * context<br>

       * the application context<br>

       * resId<br>

       * the resource ID<br>

       * priority<br>

       * the priority of the sound. Currently has no effect. Use a value of 1

       * for future compatibility.

       */

      soundId = soundPool.load(this, R.raw.office, 1);

     }

     public void click(View view) {

      /**

       * soundID a soundID returned by the load() function <br>

       * leftVolume left volume value (range = 0.0 to 1.0) <br>

       * rightVolume right volume value (range = 0.0 to 1.0) <br>

       * priority stream priority (0 = lowest priority) <br>

       * loop loop mode (0 = no loop, -1 = loop forever) rate playback<br>

       * rate (1.0 = normal playback, range 0.5 to 2.0)

       */

      int soundID = soundId;

      float leftVolume = 1.0f;

      float rightVolume = 1.0f;

      int priority = 0;

      int loop = -1;

      float rate = 1.0f;

      soundPool.play(soundID, leftVolume, rightVolume, priority, loop, rate);

     }

    }

  • 相关阅读:
    8-4:Mysql数据库编程基础知识
    adb——Android的ADB工具使用
    BroadcastReceiver--Android广播机制
    怎样投篮更准
    《算法七》(深度寻路算法)
    《算法六》(有序二叉树)
    《算法五》(N叉树定义+增删改查)
    《算法四》(二分排序+汉诺塔问题)
    《算法三》(归并排序)
    《算法二》(希尔排序+基数排序+桶排序)
  • 原文地址:https://www.cnblogs.com/freenovo/p/4469814.html
Copyright © 2020-2023  润新知