2012-01-17 9 views
2

MediaPlayerのアクティビティは、LogCatの冗長な出力に気がつくまで続きます。MediaPlayerを適切に閉じる

01-17 17:03:50.466: D/StatusBarPolicy(209): iconIndex=1 
01-17 17:03:50.476: V/StatusBarPolicy(209): cdmaLevel:1;max:4 
01-17 17:03:50.476: D/StatusBarPolicy(209): iconLevel:1 
01-17 17:03:50.476: D/StatusBarService(209): updateIcon slot=phone_signal index=20 viewIndex=14 old=StatusBarIcon(pkg=com.android.systemui id=0x7f020007 level=0 visible=true num=0) icon=StatusBarIcon(pkg=com.android.systemui id=0x7f020008 level=0 visible=true num=0) 
01-17 17:03:50.597: V/MediaPlayer(16768): getCurrentPosition 
01-17 17:03:50.597: V/MediaPlayerService(82): getCurrentPosition 
01-17 17:03:50.597: V/MediaPlayerService(82): [261] getCurrentPosition = 277943 
01-17 17:03:50.597: V/MediaPlayerService(82): [261] isPlaying: 0 
01-17 17:03:50.597: V/MediaPlayer(16768): isPlaying: 0 
01-17 17:03:50.597: V/MediaPlayerService(82): [261] isPlaying: 0 
01-17 17:03:50.597: V/MediaPlayer(16768): isPlaying: 0 
01-17 17:03:50.847: V/MediaPlayer(16768): getCurrentPosition 
01-17 17:03:50.847: V/MediaPlayerService(82): getCurrentPosition 
01-17 17:03:50.847: V/MediaPlayerService(82): [261] getCurrentPosition = 277943' 

これは、私の活動を適切に閉じていないと思います。私が使用しているコードは

cancelButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      new AlertDialog.Builder(CastrRecorder.this) 
      .setTitle("Close") 
      .setMessage("Any unsaved changes will be lost. Continue?") 
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Log.d("AlertDialog", "Positive"); 
        mPlayer.stop(); 
        mPlayer.release(); 
        Intent baseIntent = new Intent(Recorder.this, Activity.class); 
        Recorder.this.startActivity(baseIntent); 
       } 
      }) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        Log.d("AlertDialog", "Negative"); 
       } 
      }) 
      .show(); 
     } 
    }); 

です。前のコードは、ユーザーがアプリケーションを完全に終了した後も繰り返しています。私は助けることができないが、それが悪いと思う。これを防ぐには何ができますか?

答えて

2

これが重要であるかどうかはわかりませんが、stop()とrelease()の間でmPlayer.reset()を呼び出します(この問題は表示されません)。これらのログエントリを生成するのはアプリだと絶対に確信していますか?

また、ANRを引き起こす可能性があるため、メディアプレーヤーの呼び出しがUIスレッドで実行されないことが重要です。 MediaPlayerはスレッドセーフではないため、メディアプレーヤーの呼び出しがシリアル化されるように、同じバックグラウンドスレッドですべてを実行します。

+0

それは問題を修正したようです...。 LogCatは少なくとももう一杯のごみを吐き出していません。 – Carnivoris

関連する問題