0% found this document useful (0 votes)
7 views6 pages

Task No 15

The document describes a music player activity with XML layout. It initializes views, adds click listeners, and defines the activity class to play music tracks.

Uploaded by

harshal patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Task No 15

The document describes a music player activity with XML layout. It initializes views, adds click listeners, and defines the activity class to play music tracks.

Uploaded by

harshal patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Task No 15

Part 1

MusicActivity.java

package com.example.music;

import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import java.util.ArrayList;

public class MusicActivity extends AppCompatActivity {

TextView tv_songName, tv_startTime, tv_totalTime;


ImageView img_songCover, img_previous, img_backword, img_play,
img_forword, img_next;
SeekBar sb_song_Progress;

MediaPlayer mMediaPlayer;

private int currentIndex = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music);

tv_songName = findViewById(R.id.tv_music_song_name);
tv_startTime = findViewById(R.id.tv_music_start_time);
tv_totalTime = findViewById(R.id.tv_music_total_time);

img_songCover = findViewById(R.id.img_music_song_cover);
img_previous = findViewById(R.id.img_previous_song);
img_backword = findViewById(R.id.img_back_word);
img_play = findViewById(R.id.img_play);
img_forword = findViewById(R.id.img_for_word);
img_next = findViewById(R.id.img_next_press);

sb_song_Progress= findViewById(R.id.sb_music_song_progress);

ArrayList<Integer> songArrayList = new ArrayList<>();


songArrayList.add(0,R.raw.kalank_mp3);
songArrayList.add(1,R.raw.tera_fitoor);

mMediaPlayer =
MediaPlayer.create(MusicActivity.this,songArrayList.get(currentIndex));

img_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mMediaPlayer != null && mMediaPlayer.isPlaying())
{
mMediaPlayer.pause();
img_play.setImageResource(R.drawable.icon_play);
}
else
{
mMediaPlayer.start();
img_play.setImageResource(R.drawable.icon_pause);
}
}
});

MusicActivity.xml

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


<LinearLayout
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=".MusicActivity"
android:orientation="vertical"
android:background="@drawable/background_shape">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="16sp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/aclonica"
android:text="Now Playing :- "
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_music_song_name"
android:text="Song Name"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="16sp"
android:fontFamily="@font/aclonica"/>

</LinearLayout>

<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/img_music_song_cover"
android:src="@drawable/img_1"
android:layout_margin="16sp"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:layout_margin="16dp">

<TextView
android:id="@+id/tv_music_start_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="Start Time"
android:textSize="10sp"
android:textColor="@color/black"
android:textStyle="bold"
android:fontFamily="@font/aclonica"/>

<SeekBar
android:id="@+id/sb_music_song_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:progressTint="@color/black"
android:thumbTint="@color/black"/>

<TextView
android:id="@+id/tv_music_total_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="Total Time"
android:textStyle="bold"
android:textColor="@color/black"
android:textSize="10sp"
android:fontFamily="@font/aclonica"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5"
android:orientation="horizontal"
android:layout_margin="16dp">

<ImageView
android:id="@+id/img_previous_song"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_previouss"
android:layout_weight="1"/>

<ImageView
android:id="@+id/img_back_word"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_backpress"
android:layout_weight="1"/>

<ImageView
android:id="@+id/img_play"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_play"
android:layout_weight="1"/>

<ImageView
android:id="@+id/img_for_word"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_front_press"
android:layout_weight="1"/>

<ImageView
android:id="@+id/img_next_press"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_next"
android:layout_weight="1"/>

</LinearLayout>

</LinearLayout>

You might also like