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

  • 相关阅读:
    为用户分配角色 C#
    测试常用指标及工具
    MySQL Performance Schema
    CentOS7
    sysbench
    Fedora 的截屏功能
    Fedora 26 安装搜狗拼音输入法 sogoupinyin
    下载 GitHub 上保存在 AWS 的文件
    MySQL 架构
    Vagrant
  • 原文地址:https://www.cnblogs.com/baiyi168/p/6382987.html
Copyright © 2011-2022 走看看