android soundpools 能调节音量吗

&&&&Android中播放声音的两种方法MediaPlayer 和SoundPool
Android中播放声音的两种方法MediaPlayer 和SoundPool
介绍android如果使用两个工具类进行声音播放
详见转载博客
http://blog.csdn.net/ygswine/article/details/
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
移动开发下载排行Here is what I'm doing:
private SoundP
private int soundId;
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
// new SoundPool with three channels, STREAM_MUSIC, default quality
pool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
// load sound with current context, click resource, priority 1
soundId = pool.load(this, R.raw.click, 1);
// originally I wasn't using this but it seemed to help a bit
// set no loop for soundId
pool.setLoop(soundId, 0);
private void play()
Log.v(TAG, "Play the sound once!");
// half volume L & R, priority 1, loop 0, rate 1
pool.play(soundId, 0.5f, 0.5f, 1, 0, 1);
public void onDestroy()
super.onDestroy();
// release the pool
pool.release();
Originally I was using a .wav file for the click sound and the problem would occur 90% of the time.
I added setLoop and it appears to reduce it a tiny bit.
I thought it might be a problem with loading .wav files so I converted the file to .mp3.
Now the problem happens 5% of the time, but it still happens.
I built with and without the setLoop call and it appears that including it helps a tiny bit.
As you can see I have added a debug log message to ensure that I am not accidentally calling the play function twice.
According to the log output, the sound is only played once but I hear the sound twice.
I have also used several different sound files.
Some of the files seem to repeat more frequently than others.
I don't see any correlations except it happens more frequently with .wav files.
I see the problem happening on Samsung Continuum running 2.1 (min & target API: level 7).
I haven't experienced any extra looping with any market apps I've downloaded on the same device.
Unfortunately, I don't have other devices to test with.
I have only found one other person experiencing this issue and he or she was also using a Samsung device.
Here is a link to the other issue reported:
At this point I guess I'll try making a release build to see if it still happens and then maybe convert to .ogg format.
After that I'll probably try switching to MediaPlayer to see if I get the same results.
Thanks for your help.
解决方案 I was experiencing the same problem while developing for my XPeria 10 mini pro (Android 2.1). The accepted answer of this issue worked for me:
本文地址: &
下面是我在做什么: 私人泳池的S私人诠释soundId;@覆盖公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
//三个渠道新的Soundpool,STREAM_MUSIC,默认质量
池=新的Soundpool(3,AudioManager.STREAM_MUSIC,0);
//负载的声音,目前的情况下,单击资源,优先级为1
soundId = pool.load(在此,R.raw.click,1);
//本来我没有使用这一点,但它似乎对大家有点帮助
//设置无环路soundId
pool.setLoop(soundId,0);}私人无效播放(){
Log.v(TAG“,播放声音一次!”);
//一半的体积L&安培; R,优先级为1,循环0,1率
pool.play(soundId,0.5F,0.5F,1,0,1);}@覆盖公共无效的onDestroy(){
super.onDestroy();
pool.release();} 本来我是使用点击声音.wav文件,并会出现90%的时间的问题。我说setLoop,它似乎减少它一点点。我是这么认为的我转换为.mp3文件可能是与装载.wav文件的一个问题。现在的问题发生的5%的时间,但它仍然发生。我建了有和没有setLoop电话,看来,包括它有助于一点点。正如你可以看到我已经添加了一个调试日志信息,以确保我不小心调用播放功能的两倍。根据日志输出,声音只打过一次,但我听到声音的两倍。我也用几种不同的声音文件。某些文件似乎比其他人更频繁地重复。我没有看到任何相关性,除了它与.wav文件发生更频繁。我看到发生在三星的连续运行问题2.1(分和放大器;目标API:7级)。我没有经历过任何市场中的应用,我在同一设备上下载任何额外的循环。不幸的是,我没有其他设备进行测试。我只发现了另外一个人遇到这个问题,他或她还使用了三星的设备。下面是其他问题的链接报道:
在这一点上我想我会尽力做一个发布版本,看看它仍然发生,然后可能转化为.OGG格式。之后,我可能会尝试切换到MediaPlayer的,看我是否得到相同的结果。感谢您的帮助。解决方案 我遇到同样的问题,同时为我的10 XPERIA mini pro的(Android 2.1系统)。这个问题的答案接受为我工作:
本文地址: &
扫一扫关注官方微信&Android多媒体之SoundPool播放声音
Android多媒体之SoundPool播放声音
视频太卡?试试切换线路
本课时针对课程内容进行简要讲解。
在一个Android工程中,可能会使用大量的字符串作为提示信息,这些字符串都可作为字符串资源声明在配置文件中,从而实现程序的可配置性。本课时介绍字符串资源的使用方法。
本课时介绍国际化多语言的使用方法。
Android中颜色资源文件,几乎囊括了常用的各种颜色,选择颜色的时候一目了然,不必再为调色发愁。本课时介绍颜色资源的使用方法。
我们可以使用一些常用的尺寸单位来定义一些文字尺寸、视图组件的宽和高等,尺寸资源是一个数字类型的数据,被定义在res\values\dimens.xml文件中。本课时介绍尺寸资源的使用方法。
数组资源也就是一串字符串或者整数列表,经常被用于Menu和Spinner选项的保存。本课时介绍数组资源的使用方法。
Android SDK提供了一个强大的类Drawable。本课时介绍Drawable资源的使用方法。
样式是用于描述一个View或是一个窗口的显示属性的集合,样式可以指定如高度,填充,字体颜色,字体大小,背景颜色等属性。本课时介绍样式和主题的使用方法。
菜单是任何应用程序的一个重要部分,提供了透露应用程序功能和设置的通用接口。Android为开发者提供了一个简单的编程接口来实现各种条件下的标准化应用程序菜单。本课时介绍菜单资源的使用方法。
在androd手机中处理XML数据时很常见的事情,通常在不同平台传输数据的时候,就可能使用XML,XML是与平台无关的特性,被广泛运用于数据通信中。本课时介绍XML的使用方法。
在Android应用中使用assets目录下存放的资源文件,assets目录下存放的资源代表应用无法直接访问的原生资源,应用程序通过AssetManager以二进制流的形式来读取资源。本课时介绍assets资源的使用方法。
SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使用SharedPreferences完成,它提供了Android平台常规的Long长 整形、Int整形、String字符串型的保存。本课时介绍SharedPreferences存储的使用方法。
内部存储,就是将文件保存在设备内部存储器中,默认情况下,这些文件是相应程序私有的,对其他程序不透明,对用户也是不透明的,当程序卸载后,这些文件就会被删除。本课时主要介绍一般内部存储的使用方法。
所有Android设备都支持可以保存文件的共享外部存储器,这个外部存储器可以是可移动存储器(如SD卡),也可以是内置在设备中的外部存储器(不可移动)。本课时介绍一般外部存储的使用方法。
SQLite是一种关系型数据库,并且SQLite是轻量级的数据库解决方案,SQLite支持多数的SQL92标准,在一些场合下其性能优于MySql等数据库引擎。本课时介绍SQLite存储的使用方法。
SQLite是一种关系型数据库,并且SQLite是轻量级的数据库解决方案,SQLite支持多数的SQL92标准,在一些场合下其性能优于MySql等数据库引擎。本课时介绍SQLite存储的使用方法。
ContentProvider提供了在应用程序之前共享数据的一种机制,而每一个应用程序都是运行在不同的应用程序的,数据和文件在不同应用程序之间达到数据的共享不是没有可能,而是显得比较复杂,而正好Android中的ContentProvider则达到了这一需求,比如有时候我们需要操作手机里的联系人,手机里的多媒体等一些信息,我们都可以用到这个ContentProvider来达到所需。本课时介绍ContentProvider存储的使用方法。
通过调用Android的API,可以实现相册,播放器,录音和摄像等功能。本课时介绍多媒体的多种支持格式。
开发Android软件中可能经常需播放多媒体声音文件,一般使用MediaPlayer类,但该类占用资源较多,对于游戏等应用可能不是很适合,SoundPool类在SDK的android.media.SoundPool为声音池的意思。本课时介绍SoundPool的使用方法。
MediaPlayer播放音频比较简单,但要播放视频就需要SurfaceView,SurfaceView比普通的自定义View更有绘图上的优势,它支持完全的OpenGL ES库。本课时介绍MediaPlayer播放音频的使用方法。
使用VideoView播放视频简单、方便,除此之外,还可以利用MediaPlayer用来播放视频。本课时介绍MediaPlayer播放视频的使用方法。
VideoView是Android系统提供的一个媒体播放显示和控制的控件。本课时介绍VideoView播放视频的使用方法。
Android手机关于Camera的使用,一是拍照,二是摄像,由于Android提供了强大的组件功能,为此对于在Android手机系统上进行Camera的开发,我们可以使用两类方法:一是借助Intent和MediaStroe调用系统Camera App程序来实现拍照和摄像功能,二是根据Camera API自写Camera程序。本课时主要介绍Camera的使用方法。
由于对手机娱乐功能方面的需要,在Android系统中都是自带系统照相机程序的,直接调用系统的照相机程序是最便捷实现照相机功能的方式。本课时主要介绍系统拍照功能的使用方法。
在进行多媒体播放时,我们知道使用MediaPlayer类来进行处理,而对于多媒体的采样录制,在Android中使用了MediaRecorder类来进行处理。本课时主要介绍MediaRecorder录音的使用方法。
当一个Android项目开发完成后,需要打包和签名处理,这样才能放到手机中使用,当然也可以发布到Google Play上去让大家下载、让自己赚钱。本课时主要介绍应用程序打包发布的使用方法。
项目开发流程是做一个项目的开始,至关重要,它关系到整个项目的需求、设计、开发、测试和产品发布等等因素。本课时主要介绍项目开发的基本流程。
在Android应用中创建界面通常有两种方法,一种是使用xml创建布局,另一种则是在java代码中实现,与使用xml文件相比,它更加灵活、更加动态。本课时主要介绍界面的基本设计方法。
SQLite是一种流行的关系型数据库管理系统(Relational Database Management System, RDBMS),它具有以下特征:开源、符合标准、轻量级、单一层等。本课时主要介绍SQLite的使用方法。
本课时主要介绍记事本实例之呈现日志代码实现。
本课时主要介绍记事本实例之编辑添加日志代码实现。
本课时主要介绍记事本实例之添加日志附加媒体代码实现。
本课时主要介绍记事本实例之播放日志附加媒体代码实现。
只有成为VIP会员才能提问&回复,快吧!如果你还没有账号你可以一个账号。
添加新技术问题
课程 [Android多媒体之SoundPool播放声音]
中已存在问题
添加新技术问题
问题描述越详细,被解答的速度越快
有新回答时请邮件提醒我
着急,拜托快点
不急,慢慢解决
关联课程 [Android多媒体之SoundPool播放声音]
服务热线:400-678-8266下次自动登录
关注移动互联网和移动APP开发工具、开发框架、测试工具、微信开发、Android源码、Android开源类库以及各种开源组件的IT科技网站
现在的位置:
android SoundPool播放音效
MediaPlayer的缺点:
资源占用量高,延时时间较长
不支持多个音效同时播放
SoundPool主要用于播放一些较短的声音片段,CPU资源占用率低和反应延时小,还支持自行色设置声音的品质,音量,播放比率等参数,避免使用SoundPool来播放歌曲或者做游戏背景音乐,只有那些短促的密集的声音才考虑使用SoundPool播放
public SoundPool (int maxStreams, int streamType, int srcQuality)
Parameters
maxStreams the maximum number of simultaneous streams for this SoundPool object
streamType the audio stream type as described in AudioManager For example, game applications will normally use STREAM_MUSIC.
srcQuality the sample-rate converter quality. Currently has no effect. Use 0 for the default.
a SoundPool object, or null if creation failed
加载声音:
public int load (AssetFileDescriptor afd, int priority)
Parameters
afd an asset file descriptor
priority the priority of the sound. Currently has no effect. Use a value of 1 for future compatibility.
public int load (Context context, int resId, int priority)
Parameters
context the application context
resId the resource ID
priority the priority of the sound. Currently has no effect. Use a value of 1 for future compatibility.
public int load (String path, int priority)
Parameters
path the path to the audio file
priority the priority of the sound. Currently has no effect. Use a value of 1 for future compatibility.
public int load (FileDescriptor fd, long offset, long length, int priority)
Parameters
fd a FileDescriptor object
offset offset to the start of the sound
length length of the sound
priority the priority of the sound. Currently has no effect. Use a value of 1 for future compatibility.
public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)
Parameters
soundID a soundID returned by the load() function
leftVolume left volume value (range = 0.0 to 1.0)
rightVolume right volume value (range = 0.0 to 1.0)
priority stream priority (0 = lowest priority)
loop loop mode (0 = no loop, -1 = loop forever)
rate playback rate (1.0 = normal playback, range 0.5 to 2.0)
使用SoundPool播放声音的步骤:
调用SoundPool的构造器创建SoundPool的对象
调用SoundPool对象的load()方法从指定资源,文件,中加载声音,最好使用HashMap来管理所加载的声音
调用SoundPool的play方法播放声音
import java.util.HashM
import android.app.A
import android.media.AudioM
import android.media.SoundP
import android.os.B
import android.view.V
import android.view.View.OnClickL
import android.widget.B
public class SoundPoolTest extends Activity implements OnClickListener
Button bomb, shot,
// 定义一个SoundPool
SoundPool soundP
HashMap soundMap =
new HashMap();
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bomb = (Button) findViewById(R.id.bomb);
shot = (Button) findViewById(R.id.shot);
arrow = (Button) findViewById(R.id.arrow);
// 设置最多可容纳10个音频流,音频的品质为5
soundPool = new SoundPool(10
, AudioManager.STREAM_SYSTEM, 5);
// load方法加载指定音频文件,并返回所加载的音频ID。
// 此处使用HashMap来管理这些音频流
soundMap.put(1, soundPool.load(this, R.raw.bomb, 1));
soundMap.put(2, soundPool.load(this, R.raw.shot, 1));
soundMap.put(3, soundPool.load(this, R.raw.arrow, 1));
bomb.setOnClickListener(this);
shot.setOnClickListener(this);
arrow.setOnClickListener(this);
// 重写OnClickListener监听器接口的方法
public void onClick(View source)
// 判断哪个按钮被单击
switch (source.getId())
case R.id.bomb:
soundPool.play(soundMap.get(1), 1, 1, 0, 0, 1);
case R.id.shot:
soundPool.play(soundMap.get(2), 1, 1, 0, 0, 1);
case R.id.arrow:
soundPool.play(soundMap.get(3), 1, 1, 0, 0, 1);
【上篇】【下篇】}

我要回帖

更多关于 android调节系统音量 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信