2012-11-18 22 views
5

कुछ दिन पहले, मुझे अपने रिलीज़ किए गए ऐप पर एक क्रैश लॉग मिला।टोन जेनरेटर क्रैश एंड्रॉइड

त्रुटि टोन जेनरेटर से आती है, और मुझे समस्या नहीं मिल रही है।

यहां, मैं एक उलटी गिनती टाइमर हूं, जब टाइमर 0 तक पहुंचता है, ऐप एक टोन जेनरेटर लॉन्च करता है।

private void lanceMinuteur(int temps, int color){ 
    if(color == 0) 
     minuteur.setTextColor(getResources().getColor(R.color.color_important)); 
    else 
     minuteur.setTextColor(getResources().getColor(R.color.color_informative)); 

    if(chronoLance){ 
     chrono.cancel(); 
    } 
    chronoLance = true; 

    chrono = new CountDownTimer((temps + 1) * 1000, 1000) { 
     public void onTick(long millisUntilFinished) { 
      minuteur.setText(String.valueOf(millisUntilFinished/1000) + "\""); 
     } 
     public void onFinish() { 
      minuteur.setText("0\""); 
      minuteur.setTextColor(getResources().getColor(R.color.textcolor1design)); 
      chronoLance = false; 
      final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); //The error is coming from here 
      tg.startTone(ToneGenerator.TONE_PROP_ACK); 
     } 
    }.start(); 

} 

और क्रैश लॉग मैंने प्राप्त किया:

java.lang.RuntimeException: Init failed 
at android.media.ToneGenerator.native_setup(Native Method) 
at android.media.ToneGenerator.<init>(ToneGenerator.java:798) 
at ma.myperf.musculation.activ.GoPerformanceActivity$2.onFinish(GoPerformanceActivity.java:350) 
at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:150) 
at android.app.ActivityThread.main(ActivityThread.java:4385) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:507) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607) 
at dalvik.system.NativeStart.main(Native Method) 

तो क्या समस्या हो सकती है? मैंने टच जेनरेटर को पकड़ने का प्रयास किया है, लेकिन वहां नहीं था।

मुझे लगता है कि शायद उस डिवाइस पर जहां दुर्घटना हुई थी, में ऑडियोमैनेजर नहीं था। Stream_Notification?

+1

एक ही समस्या यहाँ :(http://stackoverflow.com/questions/13463691/error-generating-beep-using-tonegenerator-class –

+1

क्या 'GoPerformanceActivity.java' में अपने कोड, लाइन है 350? – dumbfingers

+0

लाइन 350 है यह लाइन अंतिम टोन जेनरेटर टीजी = नया टोन जेनरेटर (AudioManager.STREAM_NOTIFICATION, 100); यह वह जगह है जहां मैंने "// त्रुटि यहां से आ रही है" – FR073N

उत्तर

1

मैंने अपनी प्रोबम को हल करने के लिए SoundPool का उपयोग किया। मैंने पढ़ा कि साउंडमैनेजर शॉर्ट साउंड इफेक्ट खेलने का सबसे अच्छा विकल्प था, इसलिए मैंने यहां एक समाधान का उपयोग किया क्योंकि टोन जेनरेटर बहुत अस्थिर है।

public void initSounds(Context theContext, int nbMaxSons) { 
    mContext = theContext; 
    mSoundPool = new SoundPool(nbMaxSons, AudioManager.STREAM_MUSIC, 0); 
    mSoundPoolMap = new HashMap<Integer, Integer>(); 
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 
} 

public void addSound(int index, int soundID) { 
    mAvailibleSounds.add(index); 
    mSoundPoolMap.put(index, mSoundPool.load(mContext, soundID, 1)); 

} 

public void playSound(int index) { 
    // dont have a sound for this obj, return. 
    if (mAvailibleSounds.contains(index)) { 

     int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
     int soundId = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); 

     mKillSoundQueue.add(soundId); 

     // schedule the current sound to stop after set milliseconds 
     mHandler.postDelayed(new Runnable() { 
      public void run() { 
       if (!mKillSoundQueue.isEmpty()) { 
        mSoundPool.stop(mKillSoundQueue.firstElement()); 
       } 
      } 
     }, 3000); 
    } 
} 

तो मैं सोच रहा हूँ जो उपयोग ToneGenerator को दिया जा सकता है जब यह इस बार दुर्घटना।

5

मैंने पाया इस here:

ऐसा लगता है आपके आवेदन अपने मीडिया प्लेयर संसाधनों को रिहा नहीं किया जाता। जब आप ध्वनि बजाते हैं, तो आपको MediaPlayer.release() विधि को कॉल करने की आवश्यकता होती है। यदि आप बहुत सारी आवाज़ें बजा रहे हैं, तो कचरा कलेक्टर जारी रखने में सक्षम नहीं होगा।

+0

मुझे लगता है कि आप सही हैं: लेकिन जब हम वास्तव में जानते हैं कि ध्वनि कब चल रहा है ? – FR073N

संबंधित मुद्दे