之后打开我的活动3秒的Soundpool不打 [英] SoundPool not playing after 3 second of opening my activity
问题描述
我想,当用户点击一个按钮来播放声音,这种运作良好,如果我点击wothin当活动是开放的前3-5秒的按钮,但是如果我等待更多然后3-5秒出现没有声音。我还没有得到关于声音的任何错误....
任何想法,将appriciated!
更新:这是对我的HTC只发生。如果我尝试这在三星Galaxy S 2,它工作正常!!!!
在我的logcat是说:AudioHardwareQSD:AudioHardware PCM播放进入待机的办法解决这个???
@覆盖
保护无效的onCreate(捆绑savedInstanceState)
{ mSoundPoolMap =新的HashMap<整数,整数GT;();
mSoundPool =新的Soundpool(16,AudioManager.STREAM_RING,0);
mAudioManager =(AudioManager)mcontext.getSystemService(Context.AUDIO_SERVICE); mSoundPoolMap.put(1,mSoundPool.load(mcontext,R.raw.tap,1));} @覆盖
公共无效的onClick(视图v)
{
浮streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
mSoundPool.play(mSoundPoolMap.get(1),streamVolume,streamVolume,1,0,1);}
下面是我得到了这个工作不是最好的,但它的工作原理...
检查,看看是否该设备是从HTC和然后创建播放声音一个虚设通知。你也需要确保您的文件没有MP3或WAV OGG ...
公共静态无效playSound(INT指数)
{ 字符串m_strManufacture = Build.MANUFACTURER;
Log.i(TAG,设备名称:+ m_strManufacture);
如果(m_strManufacture.equals(HTC))
{
NotificationManager notificationManager =(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
通知通知=新的通知();
意图notificationIntent =新意图(mContext,mContext.getClass());
//设置的意图,因此它不会启动新活动
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
//的PendingIntent意图= PendingIntent.getActivity(mContext,0,notificationIntent,0);
// mContext.getResources()getResourceName(R.raw.ringer)。
notification.sound = Uri.parse(android.resource://com.yourpackages/raw/+声音);
notification.flags | = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0,通知); }
其他{//执行的Soundpool工作....}
I am trying to play a sound when a user clicks on a button, This works well if I click the button wothin the first 3-5 seconds of when the activity is open however if I wait more then 3-5 seconds there is no sound. I am also not getting any error regarding the sound....
Any ideas would be appriciated!
UPDATE: This is happening only on my HTC. If I try this on a Samsung Galaxy S 2 it works fine!!!!
In my logcat is says: "AudioHardwareQSD: AudioHardware pcm playback is going to standby" any workaround for this???
@Override
protected void onCreate(Bundle savedInstanceState)
{
mSoundPoolMap = new HashMap<Integer, Integer>();
mSoundPool = new SoundPool(16, AudioManager.STREAM_RING, 0);
mAudioManager= (AudioManager) mcontext.getSystemService(Context.AUDIO_SERVICE);
mSoundPoolMap.put(1, mSoundPool.load(mcontext, R.raw.tap, 1));}
@Override
public void onClick(View v)
{
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
mSoundPool.play(mSoundPoolMap.get(1), streamVolume, streamVolume, 1, 0, 1);}
Here is how I got this to work not the best but it works...
Checked to see if the device is from HTC and then created a dummy notification that plays a sound. Also you have to make sure that your file is MP3 not wav or OGG...
public static void playSound(int index)
{
String m_strManufacture = Build.MANUFACTURER;
Log.i(TAG, "Device Name: " + m_strManufacture);
if (m_strManufacture.equals("HTC"))
{
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
Intent notificationIntent = new Intent(mContext, mContext.getClass());
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// PendingIntent intent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
// mContext.getResources().getResourceName(R.raw.ringer);
notification.sound = Uri.parse("android.resource://com.yourpackages/raw/" + sound);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
else {//Do the soundpool work....}
这篇关于之后打开我的活动3秒的Soundpool不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!