安卓使用SoundPool播放较短的声音MP3(短信铃声)
来源:互联网 发布:linux vi 定位到最后 编辑:程序博客网 时间:2024/04/27 14:55
效果
代码
package com.javen.devicemange.CrazyOne.media;import android.media.AudioManager;import android.media.SoundPool;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import com.javen.devicemange.R;import java.util.HashMap;/** * Created by Administrator on 2017/2/24 0024. * 使用SoundPool播放较短的声音MP3(短信铃声) * SoundPool使用音效池的概念来管理多个短暂声音,支持多个声音同时播放 */public class SoundPoolTest extends AppCompatActivity implements View.OnClickListener { private Button one; private Button two; HashMap<Integer, Integer> soundMap; private SoundPool soundPool; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.soundpooltest); initView(); soundMap = new HashMap<>(); //设置最多可以容纳10个音频流,音频的品质5 soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5); //load方法加载指定音频文件,并返回所加载的音频id //使用HashMap来管理这些音频流 int oneId = soundPool.load(this, R.raw.one_music, 1); int twoId = soundPool.load(this, R.raw.two, 1); soundMap.put(1, oneId); soundMap.put(2, twoId); } private void initView() { one = (Button) findViewById(R.id.one); two = (Button) findViewById(R.id.two); one.setOnClickListener(this); two.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.one: //播放one_music音乐 soundPool.play(soundMap.get(1), 1, 1, 0, 0, 1); break; case R.id.two: //播放two音乐 soundPool.play(soundMap.get(2), 1, 1, 0, 0, 1); break; } }}
raw目录
布局xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/one" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="播放音乐one"/> <Button android:id="@+id/two" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="播放音乐two"/></LinearLayout>
。。。
0 0
- 安卓使用SoundPool播放较短的声音MP3(短信铃声)
- 安卓SoundPool播放声音(及具体参数解析)
- android----使用SoundPool播放声音
- android 的soundpool播放声音
- android使用SoundPool 播放短音效
- Android使用SoundPool播放短音效
- SoundPool播放声音
- soundpool无法播放声音
- 安卓SoundPool只能发出一次声音,或者没有声音
- Android 音频播放之SoundPool的使用和封装(自定义声音资源)
- Android声音播放之SoundPool
- MediaPlayer与SoundPool播放声音
- c#播放wav/mp3格式的声音
- 使用SoundPool放声音
- 使用SoundPool放声音
- 使用SoundPool放声音
- 安卓使用SoundPool音频池预加载音频,实现多音频,小音频的快速多音轨播放
- 安卓使用MediaPlayer播放asset目录下的音乐MP3和raw目录下的音乐MP3
- 优化Mychool 第六章上机
- 怎样用通俗的语言解释什么叫 REST,以及什么是 RESTful?
- 系统启动——Windows
- ArcGIS教程之DEM应用——水文分析
- 第六章上机练习
- 安卓使用SoundPool播放较短的声音MP3(短信铃声)
- Oracle数据库简介
- WINVNC源码分析(二)——图像
- 高德地图MapView和其他SurfaceView在同一个Activity中重叠显示透明问题
- 21、变量的作用域与生存期
- 用纯代码实现UIViewController之间跳转解析
- Android 应用层开发 Drawable 的一些叨叨絮
- canvas实现粒子特效
- 安卓复习之旅—Activity的启动流程