mediaplayer start and stop within dialog
<p>I've an "info" dialog and I'd like add background music. I added my music in res/raw, just open dialog there's a check by sharedpreferences. So, when an users click on "info", automatically start music, next when users click on "ok" music should be stops.</p>

<p>My code, but does not runs.</p>

<pre><code>private void Info(){
        sob();  
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.info, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view).create();
    TextView text=(TextView) findViewById(R.id.infoView1);
    builder.setCancelable(false); 
    builder.setPositiveButton("Chiudi", new DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int id) {  
               Info = 0; //checkmp=1;
               sob();
               dialog.cancel();
        }  
        });  
    builder.show();
}

public void sob(){

    MediaPlayer mp = MediaPlayer.create(this, R.raw.sob);
    SharedPreferences prefs = getSharedPreferences(PRIVATE_PREF, 0);
    int sob = prefs.getInt("sob", 0);

    if (sob == 0){
        mp.start();
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt("sob", 1);
        editor.commit();
    }
        else {
            mp.stop();
            SharedPreferences.Editor editor = prefs.edit();
            editor.putInt("sob", 0);
            editor.commit();
    }

}
</code></pre>
