Android 在开始我的活动3秒钟后未播放声音池

Android 在开始我的活动3秒钟后未播放声音池,android,audio,soundpool,Android,Audio,Soundpool,我试图在用户单击按钮时播放声音,如果我在活动打开的前3-5秒内单击按钮,效果会很好,但是如果我等待超过3-5秒,则没有声音。我也没有得到任何错误的声音 任何想法都将受到欢迎 更新:这只发生在我的HTC上。如果我在三星Galaxy S 2上试用,效果很好 在我的日志中是这样写的:“AudioHardwareQSD:AudioHardwarePCM播放将进入待机状态”对此有什么解决方法吗 @Override protected void onCreate(Bundle savedInstanceSt

我试图在用户单击按钮时播放声音,如果我在活动打开的前3-5秒内单击按钮,效果会很好,但是如果我等待超过3-5秒,则没有声音。我也没有得到任何错误的声音

任何想法都将受到欢迎

更新:这只发生在我的HTC上。如果我在三星Galaxy S 2上试用,效果很好

在我的日志中是这样写的:“AudioHardwareQSD:AudioHardwarePCM播放将进入待机状态”对此有什么解决方法吗

@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);}
@覆盖
创建时受保护的void(Bundle savedInstanceState)
{
mSoundPoolMap=newhashmap();
mSoundPool=新的声音池(16,AudioManager.STREAM_RING,0);
mAudioManager=(AudioManager)mcontext.getSystemService(Context.AUDIO\u服务);
mSoundPoolMap.put(1,mSoundPool.load(mcontext,R.raw.tap,1));}
@凌驾
公共void onClick(视图v)
{   
float streamVolume=mAudioManager.getStreamVolume(AudioManager.STREAM_环);
streamVolume=streamVolume/mAudioManager.getStreamMaxVolume(AudioManager.STREAM_环);
play(mSoundPoolMap.get(1),streamVolume,streamVolume,1,0,1);}

下面是我如何让它工作的不是最好的,但它工作得很好

检查设备是否来自HTC,然后创建一个播放声音的虚拟通知。你还必须确保你的文件是MP3而不是wav或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....} 

在这两种情况下,
mSoundPool.play()
返回的int值是多少?我在3秒内得到声音的值1。后一个的值为2。没有为任何一个获取值0。。。