Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to play sound using android MediaPlayer in dialog?
    primarykey
    data
    text
    <p>I'm trying to play sound in a dialog. But somehow, it doesnt work. I'm not sure whether it's because its in a dialog or so.</p> <pre><code>File file = new File(Environment.getExternalStorageDirectory(),"/record"); final String soundUri = file.getAbsolutePath() + "/" +childName; RelativeLayout layout = new RelativeLayout(MLT_File.this); final MediaPlayer mp = MediaPlayer.create(MLT_File.this, Uri.parse(soundUri)); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); params.setMargins(0, 20, 0, 0); LinearLayout layout2 = new LinearLayout(MLT_File.this); layout2.setLayoutParams(params); layout2.setGravity(Gravity.CENTER); final ImageButton btn = new ImageButton(MLT_File.this); btn.setImageDrawable(this.getResources().getDrawable(android.R.drawable.ic_media_play)); layout2.addView(btn); layout.addView(layout2); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(mp.isPlaying()) { mp.pause(); btn.setImageDrawable(MLT_File.this.getResources().getDrawable(android.R.drawable.ic_media_play)); }//video is playing else { mp.start(); btn.setImageDrawable(MLT_File.this.getResources().getDrawable(android.R.drawable.ic_media_pause)); } } });//onClickListener AlertDialog.Builder builder = new AlertDialog.Builder(MLT_File.this); builder.setView(layout); builder.setCancelable(false); builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub mp.stop(); itemClick (1,soundUri); } });//delete builder.setNeutralButton("Share", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub mp.stop(); itemClick (3,soundUri); } });//share builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub mp.stop(); dialog.dismiss(); } });//cancel builder.create().show(); </code></pre> <p>There is only 1 error :</p> <pre><code>01-30 16:27:29.251: E/MediaPlayer-JNI(32416): setDataSource: outside path in JNI is �x@ </code></pre> <p>I got the idea of using mediaplayer from <a href="https://stackoverflow.com/questions/3041763/android-playing-an-audio-clip-onclick">Android: Playing an audio clip onClick</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload