Android音效SoundPool问题:soundpool 1 not retry
Android音效SoundPool问题:soundpool 1 not retry
今天开发中要用到SoundPool,遇到soundpool 1 not retry无法播放声音,MediaPlay可以
后来经过一番研究,发现:
出现soundpool 1 not retry问题的代码,无法播放声音
mgr = (AudioManager) MainActivity.this.getSystemService(Context.AUDIO_SERVICE);
//初始化soundPool 对象,第一个参数是允许有多少个声音流同时播放,第2个参数是声音类型,第三个参数是声音的品质
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(MainActivity.this, R.raw.or, 1));
soundPoolMap.put(2, soundPool.load(MainActivity.this, R.raw.sd, 1));
volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
//loop:循环中的循环模式(0 =没有循环,-1 =无限循环)
soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
问题解决:这里的问题是soundPool.load(MainActivity.this, R.raw.or, 1),即 load() 声音文件后,立马 play() 播放,系统还没有准备好声音文件,所以才出了问题
这里需要你:先在其他地方load()好了,比如在构造函数里先load()好了,在需要播放的地方再调用play(),也就是要过一段时间再调用play()
这样写就没问题
mgr = (AudioManager) MainActivity.this.getSystemService(Context.AUDIO_SERVICE);
//初始化soundPool 对象,第一个参数是允许有多少个声音流同时播放,第2个参数是声音类型,第三个参数是声音的品质
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(MainActivity.this, R.raw.or, 1));
soundPoolMap.put(2, soundPool.load(MainActivity.this, R.raw.sd, 1));
volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
soundPool.play(soundPoolMap.get(1), volume, volume, 1, 0, 1f);
Android音效SoundPool问题:soundpool 1 not retry的更多相关文章
- Android音频播放之SoundPool
SoundPool 一.基本概念 在Android应用程序的开发过程中,经常需要播放多媒体文件,也许最先想到的会是MediaPlayer类了,该类提供了播放.暂停.停止及重复播放等功能性方法(该类位于 ...
- Android音频播放之SoundPool 详解
SoundPool —— 适合短促且对反应速度比较高的情况(游戏音效或按键声等) 下面介绍SoundPool的创建过程: 1. 创建一个SoundPool (构造函数) public SoundPoo ...
- Android简单的利用SoundPool进行播放铃声的实例代码
MainActivity.java package com.example.pengdonglin.soundpool_demo; import android.annotation.Suppress ...
- 修复android 5.0 Xutils的框架问题retry error, curr request is null
Android 5.0手机对xUtils-2.6.13.jar请求时会出现retry error, curr request is null 情况, 修复解决方式: 找到library/src/com ...
- Android 使用SoundPool播放音效
在Android开发中我们经常使用MediaPlayer来播放音频文件,但是MediaPlayer存在一些不足,例如:资源占用量较高.延迟时间较长.不支持多个音频同时播放等.这些缺点决定了MediaP ...
- android SoundPool播放音效
MediaPlayer的缺点: 资源占用量高,延时时间较长 不支持多个音效同一时候播放 SoundPool主要用于播放一些较短的声音片段,CPU资源占用率低和反应延时小,还支持自行色设置声音的品质,音 ...
- Android MediaPlayer播放一般音频与SoundPool播放短促的音效
[1]使用MediaPlayer实现一般的音频播放 MediaPlayer播放通常的音频文件 MediaPlayer mediaPlayer = new MediaPlayer(); if (medi ...
- Android SoundPool.play方法的音量与系统音量的关系
Android中播放音频,除了使用MediaPlayer,还可以使用SoundPool.SoundPool使用音效池的概念来管理多个短促的音效,对于需要短促的提示音的场景特别合适. 通常调用Sound ...
- Android中的音频处理------SoundPool,MediaRecorder,MediaPlayer以及RingStone总结
用Soundpool可以播一些短的反应速度要求高的声音, 比如游戏中的爆破声, 而Mediaplayer适合播放长点的. MediaRecorder主要用来录音. SoundPool载入音乐文件使用了 ...
随机推荐
- 安装node版本管理工具之NVM
nvm是个啥?nvm是一个可以让你在同一台机器上安装和切换不同版本node的工具. 你可能会问,为什么会有这个工具?有时候在开发的时候,对node版本有强制要求,有的要求用最新版本,有的要求用稳定版本 ...
- linux 命令之cut
cut是一个选取命令,就是将一段数据经过分析,取出我们想要的.一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的. (1)其语法格式为:cut [-bn] [file] 或 cut ...
- ZOJ 3962 Seven Segment Display(数位DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...
- 《精通Python设计模式》学习结构型之代理模式
这种模式,总会让人想到SRPING中的AOP, 不同语言有不同的实现方式吧. class SensitiveInfo: def __init__(self): self.users = ['nick' ...
- 《精通Python设计模式》学习之抽象工厂
这种工厂模式用得少, 可能在游戏类的编程中用得比较多吧. 这个思路清晰一定要OK的. class Frog: def __init__(self, name): self.name = name de ...
- JavaScript工程师都应懂的33个概念
最近福利发的有点多啊,各种硬干货,小伙伴们是不是觉得很爽啊.Github真的蕴含着各种各样的宝藏,难怪各个大厂也都纷纷贡献自己的代码到Github上. 所以各种干货还是会源源不断的po给大家,觉得有帮 ...
- Oracle学习笔记——点滴汇总
Oracle学习笔记——点滴汇总 http://www.botangdb.com/ Oracle GI = Grid Infrastructure = ASM + Cluster
- [翻译]Gulp.js简介
我们讨论了很多关于怎么减少页面体积,提高重网站性能的方法.有些是操作是一劳永逸的,如开启服务器的gzip压缩,使用适当的图片格式,或删除一些不必要的字符.但有一些任务是每次工作都必须反复执行的.如 新 ...
- log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
一.异常描述: log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLo ...
- 【Java】 剑指offer(49) 丑数
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 我们把只包含因子2.3和5的数称作丑数(Ugly Number). ...