Professional Documents
Culture Documents
Java (TY)
Java (TY)
Java (TY)
J THIM TRUST’S
CERTIFICATE
This is to certify that the report has been submitted by following students.
Names
Miss. NIYA DILIP SANKHE
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.
ON
Music Player
SUBMITTED BY
PROJECT GUIDE
2023-2024
Declaration
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.
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.
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 JavaGUIMusicPlayerJFrame()
{
super("Music Player");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
playButton.addActionListener(this);
pauseButton.addActionListener(this);
chooseButton.addActionListener(this);
loopButton.addActionListener(this);
add(filePathField);
add(chooseButton);
add(playButton);
add(pauseButton);
add(loopButton);
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();
}
}
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);
}
if(isLooping)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
isPaused = false;
pauseButton.setText("Pause");
}
}
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