---
title: "25、从头学Android之多媒体--使用SoundPool播放音频"
author: "mmdev"
date: "2011-12-11T18:09:00Z"
tags: []
slug: "25-android-soundpool"
draft: false
lastmod: "2012-03-22T21:25:45Z"
id: 1461850
url: "https://mmdev.iteye.com/blog/1461850"
---

**SoundPool**

![](http://hi.csdn.net/attachment/201112/11/0_1323598260FQBR.gif)

构造方法

**构造方法**

**描述**

**public SoundPool (int maxStreams, int streamType, int srcQuality)**

参数说明：

maxStreams：指定支持多少个文件

streamType：指定声音类型

srcQuality：声音品质

常见方法

**方法名称**

**描述**

**public int load (Context context, int resId, int priority)**

从资源ID所对应的资源加载声音

**public int load (AssetFileDescriptor afd, int priority)**

从原始资源文件中加载声音

**public int load (FileDescriptor fd, long offset, long length, int priority)**

从原始资源文件中加载声音并设置加载从哪开始到多长的声音文件

**public int load (String path, int priority)**

从指定文件路径加载声音

**public final void pause (int streamID)**

暂停

**public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)**

播放

参数说明：

soundID：资源ID

leftVolume：左频道声音

rightVolume：右频道声音

loop：-1代表循环，0代表不循环

rate：值0.5-2.0设置1为正常

**public final void release ()**

释放SoundPool对象资源

**public final void stop (int streamID)**

停止

**public void setOnLoadCompleteListener (SoundPool.OnLoadCompleteListener listener)**

设置监听器，在加载音乐文件完成时触发该事件

![](http://hi.csdn.net/attachment/201112/11/0_132359828034Sx.gif)

如需转载引用请注明出处：[http://blog.csdn.net/jiahui524](http://blog.csdn.net/jiahui524)