zoukankan      html  css  js  c++  java
  • Android点赞音效播放

        /**
         * 音效播放
         */
        private SoundPool mPool;
        /**
         * 音效id
         */
        private int voiceID;

    voiceID = initSoundPool();
    /**
         * 初始化SoundPool
         */
        private int initSoundPool() {
            /**
             * 21版本后,SoundPool的创建发生很大改变
             */
            //判断系统sdk版本,如果版本超过21,调用第一种
            if (Build.VERSION.SDK_INT >= 21) {
                SoundPool.Builder builder = new SoundPool.Builder();
                builder.setMaxStreams(2);//传入音频数量
                //AudioAttributes是一个封装音频各种属性的方法
                AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
                attrBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC);//设置音频流的合适的属性
                builder.setAudioAttributes(attrBuilder.build());//加载一个AudioAttributes
                mPool = builder.build();
            } else {
                mPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
            }
            //load的返回值是一个int类的值:音频的id,在SoundPool的play()方法中加入这个id就能播放这个音频
            return mPool.load(mContext, R.raw.dianzan, 1);
        }
        // 播放点赞音效
        mPool.play(voiceID, 1, 1, 0, 0, 1);    

    音效地址:http://pan.baidu.com/s/1pLbJr4n

  • 相关阅读:
    USACO 3.1
    linux 逻辑卷管理 调整分区大小
    记录一下
    ADOX创建ACCESS数据库列名的数据类型
    使用jstack分析cpu消耗过高的问题
    fastadmin添加定时任务
    linux定时任务
    技术域
    IOS div上下滑动效果
    mysql根据时间统计数据语句
  • 原文地址:https://www.cnblogs.com/baiyi168/p/6382987.html
Copyright © 2011-2022 走看看