Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Mohan </p> <p>I got your problem you want to make a player which has static image and has background sound</p> <p>here is the code</p> <p>Main.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/image" &gt; &lt;Button android:id="@+id/play" android:layout_width="100px" android:layout_height="wrap_content" android:text="Play" /&gt; &lt;Button android:id="@+id/pause" android:layout_width="100px" android:layout_height="wrap_content" android:text="Pause" /&gt; &lt;Button android:id="@+id/stop" android:layout_width="100px" android:layout_height="wrap_content" android:text="Stop" /&gt; &lt;Button android:id="@+id/info" android:layout_width="100px" android:layout_height="wrap_content" android:text="Info" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>now past your sound file in res/create "raw" directory/ your sound "foo.mp3" </p> <p>and image file in drawable/your background image "bar.png"</p> <p>now here is the code has 3 button PLAY PUSH STOP ... </p> <pre> package cm.ex.au; import java.io.IOException; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class au extends Activity { /** Called when the activity is first created. */ protected static final int PLAY = 0x101; protected static final int STOP = 0x102; protected static final int PAUSE = 0x103; int State; public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); final MediaPlayer mplayer = MediaPlayer.create(au.this,R.raw.robotrock); mplayer.stop(); // PLAY button Button play = (Button) this.findViewById(R.id.play); State = STOP; play.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // mp.prepare(); //mplayer.reset(); if (State == STOP) { try { mplayer.prepare(); } catch(IOException e) { Log.d("AudioPlayer","IOException"); } } mplayer.start(); State = PLAY; mplayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer arg0) { // End of file } }); } }); // PAUSE button Button pause = (Button) this.findViewById(R.id.pause); pause.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { mplayer.pause(); State = PAUSE; } }); // STOP button Button stop = (Button) this.findViewById(R.id.stop); stop.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { mplayer.stop(); State = STOP; } }); } } </pre> <p>and do not forget to change final MediaPlayer mplayer = MediaPlayer.create(au.this,R.raw.robotrock);</p> <p>R.raw."your sound file name "</p> <p>ok i think it is help you n joy :)</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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