Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

[ 2CEIT5PE5 MOBILE APPLICATION DEVELOPMENT]

Practical: 5

AIM- Create an MP3 player application by using service and design as shown
in below image.

Submitted By: Divyesh Patel


Enrollment number: 19012011111

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"

19012011111_Divyesh Patel Page 3


Practical: 5
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/playArrow"
android:layout_marginBottom="30dp"
android:layout_marginLeft="15dp"
/>
<!--
<com.google.android.material.floatingactionbutton.FloatingActionButton-->
<!-- android:id="@+id/pause"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:backgroundTint="#4b4643"-->
<!-- android:src="@drawable/ic_baseline_pause_24"-->
<!-- app:backgroundTint="#4b4643"-->
<!-- app:tint="#FFFFFF"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintStart_toEndOf="@+id/skipNext"-->
<!-- android:layout_marginBottom="30dp"-->
<!-- android:layout_marginLeft="10dp"-->
<!-- />-->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#4b4643"
android:src="@drawable/ic_baseline_stop_24"
app:backgroundTint="#4b4643"
app:tint="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/skipNext"
android:layout_marginBottom="30dp"
android:layout_marginLeft="10dp"
/>

<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" />

19012011111_Divyesh Patel Page 4


Practical: 5

<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"

19012011111_Divyesh Patel Page 5


Practical: 5
/>
<View
android:id="@+id/imgInfo"
android:layout_width="26dp"
android:layout_height="26dp"
android:background="@drawable/ic_baseline_info_24"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="15dp"
android:layout_marginRight="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
app:layout_constraintTop_toBottomOf="@id/textTitle"
app:layout_constraintStart_toStartOf="parent"
android:text="This Weekend"
android:textSize="14sp"
android:textColor="@color/white"/>
<View
android:id="@+id/imgHeart"
android:layout_width="26dp"
android:layout_height="26dp"
android:background="@drawable/ic_baseline_favorite_24"
app:layout_constraintTop_toBottomOf="@id/imgInfo"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="100dp"
android:layout_marginTop="15dp"
android:backgroundTint="@color/white"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="19.10k"
android:textColor="@color/white"
android:textSize="21sp"
app:layout_constraintTop_toTopOf="@+id/imgInfo"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="38dp"
android:layout_marginRight="20dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

19012011111_Divyesh Patel Page 6


Practical: 5

</androidx.constraintlayout.widget.ConstraintLayout>

gradiant_rectangle.xml

<?xml version="1.0" encoding="utf-8"?>


<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#66392a"
android:endColor="#212121"
android:centerX="1.0"
android:centerY="0.0"
android:type="radial"
android:gradientRadius="1100"/>

</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

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

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
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int):


Int {
if (!this::mediaPlayer.isInitialized){
mediaPlayer= MediaPlayer.create(this,R.raw.unstoppable)
}
var string1:String?=intent!!.getStringExtra("Service1")
if (string1=="Play") {
mediaPlayer.start()
}
// else if (string1=="Pause"){
// mediaPlayer.pause()
// }
return START_STICKY
}
19012011111_Divyesh Patel Page 8
Practical: 5

override fun onDestroy() {


mediaPlayer.stop()
super.onDestroy()
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.practical_5">

<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" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<service android:name=".MyService"></service>
</application>

</manifest>

19012011111_Divyesh Patel Page 9


Practical: 5
Output:

19012011111_Divyesh Patel Page 10

You might also like