Android点赞音效播放
生活随笔
收集整理的這篇文章主要介紹了
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());//加載一個AudioAttributesmPool = 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);
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());//加載一個AudioAttributesmPool = 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
轉載于:https://www.cnblogs.com/baiyi168/p/6382987.html
總結
以上是生活随笔為你收集整理的Android点赞音效播放的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js本地时钟
- 下一篇: 关于服务器返回信息的Unicode转码的