Java (TY)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

H.

J THIM TRUST’S

THEEM COLLEGE OF ENGINEERING

Boisar chillar Road, Boisar (E), Tal. Palghar

Dist Palghar, Pin- 401501

ACADEMIC YEAR 2023-24

CERTIFICATE

This is to certify that the report has been submitted by following students.

Names
Miss. NIYA DILIP SANKHE

Miss. SAFA SALIM SAYED

Miss. VAIBHAVI RAVINDRA MORE

Miss. SAUNDARYA DINESH RAUT

This project work has been completed by 2022-23 Year student of course COMPUTER
ENGINEERING as a part of work prescribes by Maharashtra state Board of technical
Education Mumbai.

We have guided and assisted the students for the above work, which has been
Satisfactory/good/Very Good.

Sign of Teacher Sign of H.O.D Sign of principal

(Sarika Patil) (Rosy Bhoi) (Sayyad Layak)


PROJECT REPORT

ON

Music Player

SUBMITTED BY

Miss. NIYA DILIP SANKHE

Miss. SAFA SALIM SAYED

Miss. VAIBHAVI RAVINDRA MORE

Miss. SAUNDARYA DINESH RAUT

PROJECT GUIDE

Prof. Sarika Patil

DEPARTMENT OF COMPUTER ENGINNERING


H.J THIM TRUST’S

THEEM COLLEGE OF ENGNEERING

Boisar chillar Road, Boisar (E), Tal. Palghar

Dist. Palghar, Pin- 401501

2023-2024
Declaration

I declare that this written submission represents my ideas in my own words


and where others ideas or words have been included: I have adequately
cited and referred the original sources. I also declare that I have adhered to
all principles of academics honestly and integrity have not misrepresented
or fabricated or falsified my ideas/ data/ fact/ source in my submission. I
understand that any violence of the above will be cause for disciplinary
action by the institute and can also evolve penal action from the source
which has thus not been properly citied or from whom proper permission
has not been taken when needed.

MISS. NIYA DILIP SANKHE

MISS. SAFA SALIM SAYED

MISS. VAIBHAVI RAVINDRA MORE

MISS. SAUNDARYA DINESH RAUT

Date: _____________________________
Acknowledgement

It’s our pleasure to take this opportunity to thank with deep sense of
gratitude to our guide, staff members of Computer department and
everyone who have directly or indirectly contributed to my project as a
success. With immense pleasure I express my deep sense of gratitude and
vote of thanks to our project guide. Lectr. Sarika Patil, for his constant
interest, motivation and valuable guidance during work and completion of
this project report.

We are very thankful to Lectr. Sarika Patil and the whole staff of the
Computer department for giving us the opportunity to work on this project
and for the extensive co-operation and guidance. We offer sincere thanks to
prin. Sayyad layak and Prof. Rosy Bhoi (head of department) for their
inspiration and providing full administrative support and department
infrastructure facilities for this report.

We are also very thankful to all those who supported us without which
project would not have been completed successfully.

MISS. NIYA DILIP SANKHE

MISS. SAFA SALIM SAYED

MISS. VAIBHAVI RAVINDRA MORE

MISS. SAUNDARYA DINESH RAUT


Music Player

In This Tutorial, we will learn to create a simple music player in Java. The
music player in which we can start a song, pause a song and restart a song.
We will use swings ie. JButton, JFrame for this task. We can create the
music player using any IDE ie. Notepad, Notepad++.
In this project, MediaPlayer is the name of the class. We are extending
JFrame because we will use JFrame and JButton etc for creating the front-
end of the media player. Using NetBeans we can easily drag and drop the
required fields Netbeans will automatically generate the code for us.

How to run the project?


We are using buttons on the front end to choose the song. First, we need to
select the name of the song, after selecting the name we can press the play
button to play the song.

We are using buttons to select the song. Further, we are using these
methods to assign a particular song to the player.

Program:-
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.filechooser.*;

public class JavaGUIMusicPlayerJFrame extends JFrame implements ActionListener {


private JTextField filePathField;
private JButton playButton;
private JButton pauseButton;
private JButton chooseButton;
private JButton loopButton;
private boolean isPaused;
private boolean isLooping = false;
private JFileChooser fileChooser;
private Clip clip;

public JavaGUIMusicPlayerJFrame()
{
super("Music Player");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

filePathField = new JTextField(20);


playButton = new JButton("Play");
pauseButton = new JButton("Pause");
chooseButton = new JButton("Choose File");
loopButton = new JButton("Loop");
isPaused = false;
isLooping = false;

playButton.addActionListener(this);
pauseButton.addActionListener(this);
chooseButton.addActionListener(this);
loopButton.addActionListener(this);

add(filePathField);
add(chooseButton);
add(playButton);
add(pauseButton);
add(loopButton);

fileChooser = new JFileChooser(".");


fileChooser.setFileFilter(new FileNameExtensionFilter("WAV Files", "wav"));

setSize(500, 100);
setLocationRelativeTo(null);
setVisible(true);
}

@Override
public void actionPerformed(ActionEvent event) {

if (event.getSource() == playButton)
{
playMusic();
}
else if (event.getSource() == pauseButton)
{
pauseMusic();
}
else if (event.getSource() == chooseButton)
{
chooseFile();
}
else if (event.getSource() == loopButton)
{
toggleLoop();
}
}

private void playMusic() {

if (clip != null && clip.isRunning())


{
clip.stop();
}

try
{
File file = new File(filePathField.getText());
AudioInputStream audioIn = AudioSystem.getAudioInputStream(file);

clip = AudioSystem.getClip();
clip.open(audioIn);

if (isLooping)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}

clip.start();

}
catch(Exception e)
{
System.out.println(e);
}

private void pauseMusic()


{
if (clip != null && clip.isRunning())
{
clip.stop();
isPaused = true;
pauseButton.setText("Resume");
}
else if (clip != null && isPaused)
{
clip.start();

if(isLooping)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}

isPaused = false;
pauseButton.setText("Pause");
}
}

private void chooseFile()


{
fileChooser.setCurrentDirectory(new File("."));
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
filePathField.setText(selectedFile.getAbsolutePath());
}
}

private void toggleLoop()


{
isLooping = !isLooping;
if (isLooping)
{
loopButton.setText("Stop Loop");

if(clip.isRunning())
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
}
else
{
loopButton.setText("Loop");

if(clip.isRunning())
{
clip.loop(0);
}
}
}
public static void main(String[] args) {
new JavaGUIMusicPlayerJFrame();
}
}

Output:-
Reference:-

1. MSBTE textbook

2. Geeksforgeeks.org

3. Tutorialspoint.com

You might also like