Music App



Develop Android Music application
Step 1.  Create a new Project.
Step 2.  Create an Activity
Step 3.  Go to the design view and select the Text Fields section in the Palette and locate Plain Text
Step 4.  Drag a Button from the Form Widgets section into the layout and design a GUI as given below.
multimedia.jpg
Step 5. Switch to the Text view, XML layout file and verify that the file looks similar to the following listing.

<?xml version="1.0" encoding="utf-8"?>
<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"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          tools:context="idamithw.music.MainActivity"
          android:id="@+id/meia"
          android:background="@drawable/road">

          <LinearLayout
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true">

          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="PLAY"
          android:id="@+id/button2"
          android:onClick="playButtnClicked"
          android:layout_alignParentTop="true"
          android:layout_gravity="bottom" />

          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Pause"
          android:id="@+id/button"
          android:layout_centerVertical="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_gravity="bottom"
          android:onClick="PauseButtonClicked"/>

          <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Stop"
          android:id="@+id/button3"
          android:layout_gravity="bottom"
          android:onClick="StopButonClicked"/>
          </LinearLayout>
</RelativeLayout>

Step 6. Change your MainActivity class as given in this sample. Note that onClick will be called based on the OnClick property of your button.

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
          MediaPlayer mp ;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.activity_main);
                   redyToPlay();
          }

          public void redyToPlay()
          {
                   mp = MediaPlayer.create(this,R.raw.we);
          }

          public void playButtnClicked(View view) {
                   mp.start();
          }

           
public void PauseButtonClicked(View view) {
                    mp.pause();
          }

           
public void StopButonClicked(View view) {
                   mp.stop();
                   redyToPlay();
          }
}

Comments

Popular posts from this blog

Google Map

SQL Lite Database Save

SQL Lite Database Save