• 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);

     }

    }

  • 相关阅读:
    MAC OS下安装Minizip
    MAC OS下安装pkg_config
    计算机图形学-几何变换
    计算机图形学-图形系统
    Unix&Linux大学教程 读书笔记【1-3章】
    Mixins 混入选项操作
    watch监控,对比新值和旧值做出相应判断
    用.native修饰器来对外部组件进行构造器内部方法的调用以及用原生js获取构造器里的方法
    methods 方法选项
    computed 计算选项
  • 原文地址:https://www.cnblogs.com/freenovo/p/4469814.html
Copyright © 2020-2023  润新知