1

ユーザーがボタンをクリックしたときにサウンドを再生しようとしています。これは、アクティビティが開いているときの最初の 3 ~ 5 秒の間にボタンをクリックするとうまく機能しますが、3 ~ 5 秒以上待つとサウンドがありません。 . また、音に関するエラーも発生していません....

どんなアイデアでも歓迎します!

更新: これは私の HTC でのみ発生しています。これを Samsung Galaxy S 2 で試してみると、問題なく動作します!!!!

私のlogcatには次のように書かれています:「AudioHardwareQSD:AudioHardware pcmの再生がスタンバイになります」これに対する回避策はありますか???

@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);}
4

1 に答える 1

0

これが最善ではありませんが、うまくいくようにする方法です...

デバイスが HTC のものかどうかを確認し、サウンドを再生するダミーの通知を作成しました。また、ファイルがwavやOGGではなくMP3であることを確認する必要があります...

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....} 
于 2012-09-05T09:41:17.390 に答える