To Understand Android Multimedia APIs Develop Applications of MP3 Player
- XML Code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="44dp"
android:layout_marginTop="38dp"
android:text="Play" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Pause" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/button2"
android:text="Stop" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="175dp"
android:text="" />
</RelativeLayout>
- JAVA Code :
package com.example.pra8;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
public class Pra8 extends Activity {
Button bt1,bt2,bt3;
TextView tv;
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pra8);
mp = MediaPlayer.create(this, R.raw.song);
bt1 = (Button)findViewById(R.id.button1);
bt2 = (Button)findViewById(R.id.button2);
bt3 = (Button)findViewById(R.id.button3);
tv = (TextView)findViewById(R.id.textView1);
tv.setText(R.raw.song);
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp.start();
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp.pause();
}
});
bt3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mp.stop();
Intent i = new Intent(Pra8.this,Pra8.class);
startActivity(i);
}
});
}
}
- OUTPUT :
No comments:
Post a Comment