Divyesh Patel - Practical-5 - MAD
Divyesh Patel - Practical-5 - MAD
Divyesh Patel - Practical-5 - MAD
Practical: 5
AIM- Create an MP3 player application by using service and design as shown
in below image.
Department of Computer
Engineering/Information Technology
Practical: 5
Create an MP3 player application by using service and design as shown in
below image.
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/gradient_rectangle"
>
<View
android:id="@+id/Waveform"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:layout_marginTop="35dp"
android:background="@drawable/ic_waveform_1635076952293"
app:layout_constraintTop_toBottomOf="@id/imgCard"
app:layout_constraintRight_toRightOf="parent"
/>
<View
android:id="@+id/btnMenu"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_baseline_menu_24"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="14dp"
android:layout_marginLeft="20dp"
/>
<View
android:id="@+id/btnPlaylistPlay"
android:layout_width="34dp"
android:layout_height="34dp"
android:background="@drawable/ic_baseline_playlist_play_24"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="14dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="20dp"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
19012011111_Divyesh Patel Page 2
Practical: 5
android:id="@+id/btnShuffle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#4b4643"
android:src="@drawable/ic_baseline_shuffle_24"
app:backgroundTint="#4b4643"
app:tint="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="30dp"
android:layout_marginLeft="15dp"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/SkipPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#4b4643"
android:src="@drawable/ic_baseline_skip_previous_24"
app:backgroundTint="#4b4643"
app:tint="#FFFFFF"
app:layout_constraintStart_toEndOf="@+id/btnShuffle"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="30dp"
android:layout_marginLeft="15dp"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/playArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#79371f"
android:src="@drawable/ic_baseline_play_arrow_24"
app:backgroundTint="#79371f"
app:tint="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/SkipPrevious"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/skipNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#4b4643"
android:src="@drawable/ic_baseline_skip_next_24"
app:backgroundTint="#4b4643"
app:tint="#FFFFFF"
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MP3 Player"
android:textColor="#FFFFFF"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/imgCard"
android:layout_width="match_parent"
android:layout_height="350dp"
app:cardCornerRadius="20dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="50dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardElevation="20dp"
>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/song"/>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cv_info"
android:layout_width="match_parent"
android:layout_height="90dp"
app:cardCornerRadius="30dp"
app:layout_constraintTop_toBottomOf="@+id/imgCard"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:backgroundTint="#36454f"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="Dosti Music Video"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
gradiant_rectangle.xml
</shape>
strings.xml
<resources>
<string name="app_name">19012011111_Practical-5</string>
</resources>
MainActivity.kt
package com.example.practical_5
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.google.android.material.floatingactionbutton.FloatingActionButton
val btn_play:FloatingActionButton=findViewById(R.id.playArrow)
val btn_stop:FloatingActionButton=findViewById(R.id.stop)
btn_play.setOnClickListener{
19012011111_Divyesh Patel Page 7
Practical: 5
var tent:Intent=Intent(applicationContext,MyService::class.java)
intent.putExtra("Service1","Play")
startService(intent)
}
// btn_pause.setOnClickListener{
// var
intent:Intent=Intent(applicationContext,MyService::class.java)
// intent.putExtra("Service1","Pause")
// startService(intent)
// }
btn_stop.setOnClickListener{
var
intent:Intent=Intent(applicationContext,MyService::class.java)
stopService(intent)
}
}
}
MyService.kt
package com.example.practical_5
import android.app.Service
import android.content.Intent
import android.media.MediaPlayer
import android.os.IBinder
class MyService:Service() {
lateinit var mediaPlayer:MediaPlayer
override fun onBind(p0: Intent?): IBinder? {
return null
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practical5">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>