Source code of Media Player App
Insert songs and media in android apps with help of media player class.
MainActivity.java
package com.singh.jassi.mediaplayer;
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);
mp=MediaPlayer.create(this,R.raw.song);
}
public void start(View vv)
{
mp.start();
}
public void stop(View x)
{
mp.stop();
}
public void pause(View jj)
{
mp.pause();
}
}
activity_main.xml
<?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:id="@+id/activity_main"
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="com.singh.jassi.mediaplayer.MainActivity">
<Button
android:text="Start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="33dp"
android:layout_marginTop="204dp"
android:id="@+id/button"
android:onClick="start"
/>
<Button
android:text="stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="62dp"
android:id="@+id/button2"
android:layout_alignBaseline="@+id/button"
android:layout_alignBottom="@+id/button"
android:layout_alignParentEnd="true"
android:onClick="stop"
/>
<Button
android:text="pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:layout_toEndOf="@+id/button"
android:layout_marginTop="52dp"
android:id="@+id/button3"
android:onClick="pause"
/>
</RelativeLayout>
Create awesome image scaling animation app - Free code to download
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.singh.jassi.mediaplayer">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Comments
Post a Comment