首页 > 移动平台 > 详细

Android点赞音效播放

时间:2017-02-09 17:40:13      阅读:465      评论:0      收藏:0      [点我收藏+]
    /**
     * 音效播放
     */
    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

Android点赞音效播放

原文:http://www.cnblogs.com/baiyi168/p/6382987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!