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

PROJECT REPORT ON

AUDIO PLAYER
Project Report submitted in partial fulfillment of
The requirements for the degree of

BACHELOR OF COMPUTER APPLICATION

Of

WEST BENGAL UNIVERSITY OF TECHNOLOGY


By

Sinjini Patra, Roll no: 29201216006


Riya Patra, Roll no: 29201216017
Bratati Banerjee, Roll No: 29201216041
Under the guidance of

Tanmay De

DEPARTMENT OF BCA

NETAJI SUBHASH ENGINEERING COLLEGE


TECHNO CITY, GARIA, KOLKATA – 700 152
<< Academic year of pass out e.g. 2018-19>>
CERTIFICATE
This is to certify that this project report titled Audio player submitted in partial fulfillment of

requirements for award of the degree Bachelor of Computer Application of West Bengal University of

Technology is a faithful record of the original work carried out by,

Sinjini Patra, Roll no: 29201216006, Regd. No: 162921010046 and 2016-2017
Riya Patra, Roll no: 29201216017, Regd. No: 162921010035 and 2016-2017
Bratati Banerjee, Roll no: 29201216041, Regd. No. 162921010011 and 2016-2017

under my guidance and supervision.

It is further certified that it contains no material, which to a substantial extent has been submitted for the

award of any degree/diploma in any institute or has been published in any form, except the assistances

drawn from other sources, for which due acknowledgement has been made.

Date:……….. Tanmay De Guide’s signature

Sd/ Mitali Goswami

Head of the Department

<<BCA>>

NETAJI SUBHASH ENGINEERING COLLEGE


TECHNO CITY, GARIA, KOLKATA – 700 152
DECLARATION
We hereby declare that this project report titled

AUDIO PLAYER

is our own original work carried out as a under graduate student in Netaji Subhash Engineering College

except to the extent that assistances from other sources are duly acknowledged.

All sources used for this project report have been fully and properly cited. It contains no material which

to a substantial extent has been submitted for the award of any degree/diploma in any institute or has

been published in any form, except where due acknowledgement is made.

Student’s names: Signatures: Dates:

SINJINI PATRA ……………………….. ……………………

RIYA PATRA ……………………. ……………………

BRATATI BANERJEE ……………………….. ……………………


CERTIFICATE OF APPROVAL

We hereby approve this dissertation titled

AUDIO PLAYER

carried out by

Sinjini Patra, Roll no: 29201216006, Regd. No: 162921010046 and 2016-2017
Riya Patra, Roll no: 29201216017, Regd. No: 162921010035 and 2016-2017
Bratati Banerjee, Roll no: 29201216041, Regd. No. 162921010011 and 2016-2017

under the guidance of

TANMAY DE

of Netaji Subhash Engineering College, Kolkata in partial fulfillment of requirements for award of the

Bachelor of Computer Application of West Bengal University of Technology

Date: ..………..

Examiners’ signatures:

1. ………………………………………….

2. ………………………………………….

3. ………………………………………….
Acknowledgement

First of all, we are thankful to ATA INFOTECH VENTURES PVT. LTD. For

training on JAVA for their necessary guidance. We take these opportunity

express our profound gratitude and deep regards to HOD, Mrs.Mitali Goswami

and GUIDE, Mr. Tanmay De for their exemplary guidance, monitoring and

constant encouragement throughout the course of this web project.

The blessings, help and guidance given by them time to time shall carry us a

Long journey of our life on which we are to embark.

SINJINI PATRA

RIYA PATRA

BRATATI BANERJEE
CONTENTS

PRELIMINARIES PAGE NO.


 Certificate …………….
 Declaration …………….
 Certificate Of Approval …………....
 Acknowledgement ……………..
1. Abstract ……………..
2. Introduction ……………...
3. Problem Statement ……………...
4. Code Design ……………...
5. System Design ..………….
a)Design ……………….
b)Algorithm ……………
c) Functional Flowchart …………..
d)Context Diagram …………..
e)DFD …………..
f) State Transition Diagram …………..
6. Modular pseudo Code ……………
7. Snapshot of Output ……………
8. Scope ……………
9. Limitations ……………

Conclusion ……………
ABSTRACT

Module 1:

To provide a media player interface on Bluetooth enabled

mobile device. In this module there will be a media player to

play songs on a desktop and its instance interface on mobile

device from where we can control playback remotely.

Module 2:

Streaming with above media player. Streaming of any song

will be done by media player when it gets a request from its

counterpart player on mobile device to do so. With this a


person can listen to any song from media player library by

streaming done with Bluetooth protocol .

Aim :

1. To learn interaction between a desktop and a Bluetooth

enabled mobile device.

2. To provide a virtual command prompt on mobile device to

perform various tasks remotely.

3. To provide new user experience for music freaks so that

they can take advantage of their giant music library (that’s on

PC) from anywhere wihin range of class B Bluetooth .

4. To learn about all the technical restrictions that a developer

can face while learning mobile development using JAVA.


d) CONTEXT DIAGRAM:

e) DFD(LEVEL 1):
 DFD (LEVEL 2):

PLAY PROCESS
MANAGE PLAY-LIST

f)STATE TRANSITION DIAGRAM:


State Transition Diagram shows various states of

player when user takes different commands. Here from

above diagram programmer can easily interpret the

required objective and easily understand the

functionality. We have three states in player:-


1. play

2. pause

3. Stop

Play state is achieved by taking play action, it can be

directed from stop state as well aspaused state. Pause

state is achieved when user takes pause command.

Commonly there isplay<>pause state interchange

done frequently. Stop state activates when user takes

stop command or playing song finishes.


MODULAR PSEUDO CODE

package net.codejava.audio;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class AudioPlayer implements LineListener {


private static final int SECONDS_IN_HOUR = 60 * 60;
private static final int SECONDS_IN_MINUTE = 60;
public void load(String audioFilePath)
throws UnsupportedAudioFileException, IOException,
LineUnavailableException {
File audioFile = new File(audioFilePath);

AudioInputStream audioStream = AudioSystem


.getAudioInputStream(audioFile);
AudioFormat format = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
audioClip = (Clip) AudioSystem.getLine(info);
audioClip.addLineListener(this);
audioClip.open(audioStream);
}
public long getClipSecondLength() {
return audioClip.getMicrosecondLength() / 1_000_000;
}
public String getClipLengthString()
{String length = "";
long hour = 0;
long minute = 0;
long seconds = audioClip.getMicrosecondLength() / 1_000_000;
System.out.println(seconds);
if (seconds >= SECONDS_IN_HOUR) {
hour = seconds / SECONDS_IN_HOUR;
length = String.format("%02d:", hour);
}
else
{
length += "00:";
}

minute = seconds - hour * SECONDS_IN_HOUR;


if (minute >= SECONDS_IN_MINUTE) {
minute = minute / SECONDS_IN_MINUTE;
length += String.format("%02d:", minute);

}
Else
{
minute = 0;
length += "00:";
}

long second = seconds - hour * SECONDS_IN_HOUR - minute *


SECONDS_IN_MINUTE;

length += String.format("%02d", second);

return length;

void play() throws IOException {

audioClip.start();
playCompleted = false;
isStopped = false;

while (!playCompleted) {

try {
Thread.sleep(1000);
}
catch (InterruptedException ex)
ex.printStackTrace();
if (isStopped) {
audioClip.stop();
break;
}
if (isPaused) {
audioClip.stop();
}
Else
{
System.out.println("!!!!");
audioClip.start();
}
}
}

audioClip.close();

public void stop() {


isStopped = true;
}

public void pause() {


isPaused = true;
}

public void resume()


{
isPaused = false;
}

public void update(LineEvent event) {


LineEvent.Type type = event.getType();
if (type == LineEvent.Type.STOP) {
System.out.println("STOP EVENT");
if (isStopped || !isPaused) {
playCompleted = true;
}
}
}

public Clip getAudioClip() {


return audioClip;
}
}

package net.codejava.audio;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import javax.sound.sampled.Clip;
import javax.swing.JLabel;
import javax.swing.JSlider;

public class PlayingTimer extends Thread


{
private DateFormat dateFormater = new SimpleDateFormat("HH:mm:ss");
private boolean isRunning = false;
private boolean isPause = false;
private boolean isReset = false;
private long startTime;
private long pauseTime;
private JLabel labelRecordTime;
private JSlider slider;
private Clip audioClip;

public void setAudioClip(Clip audioClip)


{
this.audioClip = audioClip;
}

PlayingTimer(JLabel labelRecordTime, JSlider slider)


{
this.labelRecordTime = labelRecordTime;
this.slider = slider;
}

public void run()


{
isRunning = true;

startTime = System.currentTimeMillis();

while (isRunning)
{
try {
Thread.sleep(100);
if (!isPause)
{
if (audioClip != null && audioClip.isRunning())
{
labelRecordTime.setText(toTimeString());
int currentSecond = (int)
audioClip.getMicrosecondPosition() / 1_000_000;
slider.setValue(currentSecond);
}
}
else
{
pauseTime += 100;
}
}
catch (InterruptedException ex)
{
ex.printStackTrace();
if (isReset)
{
slider.setValue(0);
labelRecordTime.setText("00:00:00");
isRunning = false;
break;
}
}
}
}

void reset()
{
isReset = true;
isRunning = false;
}

void pauseTimer()
{
isPause = true;
}

void resumeTimer()
{
isPause = false;
}

private String toTimeString()


{
long now = System.currentTimeMillis();
Date current = new Date(now - startTime - pauseTime);
dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
String timeCounter = dateFormater.format(current);
return timeCounter;
}
}
package net.codejava.audio;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;

public class SwingAudioPlayer extends JFrame implements ActionListener


{
private AudioPlayer player = new AudioPlayer();
private Thread playbackThread;
private PlayingTimer timer;

private boolean isPlaying = false;


private boolean isPause = false;

private String audioFilePath;


private String lastOpenPath;

private JLabel labelFileName = new JLabel("Playing File:");


private JLabel labelTimeCounter = new JLabel("00:00:00");
private JLabel labelDuration = new JLabel("00:00:00");

private JButton buttonOpen = new JButton("Open");


private JButton buttonPlay = new JButton("Play");
private JButton buttonPause = new JButton("Pause");

private JSlider sliderTime = new JSlider();

private ImageIcon iconOpen = new ImageIcon(getClass().getResource(


"/net/codejava/audio/images/Open.png"));
private ImageIcon iconPlay = new ImageIcon(getClass().getResource(
"/net/codejava/audio/images/Play.gif"));
private ImageIcon iconStop = new ImageIcon(getClass().getResource(
"/net/codejava/audio/images/Stop.gif"));
private ImageIcon iconPause = new ImageIcon(getClass().getResource(
"/net/codejava/audio/images/Pause.png"));

public SwingAudioPlayer()
{
super("Java Audio Player");
setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets(5, 5, 5, 5);
constraints.anchor = GridBagConstraints.WEST;

buttonOpen.setFont(new Font("Sans", Font.BOLD, 14));


buttonOpen.setIcon(iconOpen);

buttonPlay.setFont(new Font("Sans", Font.BOLD, 14));


buttonPlay.setIcon(iconPlay);
buttonPlay.setEnabled(false);

buttonPause.setFont(new Font("Sans", Font.BOLD, 14));


buttonPause.setIcon(iconPause);
buttonPause.setEnabled(false);

labelTimeCounter.setFont(new Font("Sans", Font.BOLD, 12));


labelDuration.setFont(new Font("Sans", Font.BOLD, 12));
sliderTime.setPreferredSize(new Dimension(400, 20));
sliderTime.setEnabled(false);
sliderTime.setValue(0);

constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 3;
add(labelFileName, constraints);

constraints.anchor = GridBagConstraints.CENTER;
constraints.gridy = 1;
constraints.gridwidth = 1;
add(labelTimeCounter, constraints);

constraints.gridx = 1;
add(sliderTime, constraints);

constraints.gridx = 2;
add(labelDuration, constraints);

JPanel panelButtons = new JPanel(new


FlowLayout(FlowLayout.CENTER, 20, 5));
panelButtons.add(buttonOpen);
panelButtons.add(buttonPlay);
panelButtons.add(buttonPause);

constraints.gridwidth = 3;
constraints.gridx = 0;
constraints.gridy = 2;
add(panelButtons, constraints);

buttonOpen.addActionListener(this);
buttonPlay.addActionListener(this);
buttonPause.addActionListener(this);

pack();
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}

public void actionPerformed(ActionEvent event)


{
Object source = event.getSource();
if (source instanceof JButton)
{
JButton button = (JButton) source;
if (button == buttonOpen)
{
openFile();
}
else if (button == buttonPlay)
{
if (!isPlaying) {
playBack();
}
else {
stopPlaying();
}
}
else if (button == buttonPause)
{
if (!isPause) {
pausePlaying();
}
Else
{
resumePlaying();
}
}
}
}

private void openFile()


{
JFileChooser fileChooser = null;

if (lastOpenPath != null && !lastOpenPath.equals(""))


{
fileChooser = new JFileChooser(lastOpenPath);
}
else {
fileChooser = new JFileChooser();
}

FileFilter wavFilter = new FileFilter()


{
@Override
public String getDescription() {
return "Sound file (*.WAV)";
}

@Override
public boolean accept(File file)
{
if (file.isDirectory()) {
return true;
}
else {
return
file.getName().toLowerCase().endsWith(".wav");
}
}
};

fileChooser.setFileFilter(wavFilter);
fileChooser.setDialogTitle("Open Audio File");
fileChooser.setAcceptAllFileFilterUsed(false);

int userChoice = fileChooser.showOpenDialog(this);


if (userChoice == JFileChooser.APPROVE_OPTION)
{
audioFilePath =
fileChooser.getSelectedFile().getAbsolutePath();
lastOpenPath = fileChooser.getSelectedFile().getParent();
if (isPlaying || isPause)
{
stopPlaying();
while (player.getAudioClip().isRunning())
{
try {
Thread.sleep(100);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}
}
}
playBack();
}
}

private void playBack()


{
timer = new PlayingTimer(labelTimeCounter, sliderTime);
timer.start();
isPlaying = true;
playbackThread = new Thread(new Runnable()
{

@Override
public void run()
{
try
{

buttonPlay.setText("Stop");
buttonPlay.setIcon(iconStop);
buttonPlay.setEnabled(true);

buttonPause.setText("Pause");
buttonPause.setEnabled(true);

player.load(audioFilePath);
timer.setAudioClip(player.getAudioClip());
labelFileName.setText("Playing File: " +
audioFilePath);
sliderTime.setMaximum((int)
player.getClipSecondLength());

labelDuration.setText(player.getClipLengthString());
player.play();

resetControls();

}
catch (UnsupportedAudioFileException ex)
{

JOptionPane.showMessageDialog(SwingAudioPlayer.this,
"The audio format is unsupported!",
"Error", JOptionPane.ERROR_MESSAGE);
resetControls();
ex.printStackTrace();
}
catch (LineUnavailableException ex)
{

JOptionPane.showMessageDialog(SwingAudioPlayer.this,
"Could not play the audio file because
line is unavailable!", "Error", JOptionPane.ERROR_MESSAGE);
resetControls();
ex.printStackTrace();
}
catch (IOException ex)
{

JOptionPane.showMessageDialog(SwingAudioPlayer.this,
"I/O error while playing the audio file!",
"Error", JOptionPane.ERROR_MESSAGE);
resetControls();
ex.printStackTrace();
}

}
});
playbackThread.start();
}

private void stopPlaying() {


isPause = false;
buttonPause.setText("Pause");
buttonPause.setEnabled(false);
timer.reset();
timer.interrupt();
player.stop();
playbackThread.interrupt();
}

private void pausePlaying() {


buttonPause.setText("Resume");
isPause = true;
player.pause();
timer.pauseTimer();
playbackThread.interrupt();
}

private void resumePlaying() {


buttonPause.setText("Pause");
isPause = false;
player.resume();
timer.resumeTimer();
playbackThread.interrupt();
}

private void resetControls() {


timer.reset();
timer.interrupt();

buttonPlay.setText("Play");
buttonPlay.setIcon(iconPlay);

buttonPause.setEnabled(false);

isPlaying = false;
public static void main(String[] args) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassNam
e());
}
catch (Exception ex)
{
ex.printStackTrace();
}

SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
new SwingAudioPlayer().setVisible(true);
}
});
}

SNAPSHOT OF OUTPUT:
INTRODUCTION
Audio Player involves an ever-expanding set of
specialized tools.Each year, there are the number of
applications using audio increases.

There are many possible tools and technologies of


abundance of shareware and freeware music and audio
software available.

In the past 20 years, audio has moved from analog


recording as the playback media to totally digital
surround sound playback.

Once, music could only be recorded by a live group of


players. Today, the Musical Instrument Digital
Interface(MIDI), the sequencer, sound cards, and
synthesizers allow anyone to create music right on their
desktop. Even a modest setup can create surprisingly
realistic audio tracks. It probably have many of these
tools in your computer already.

“Even if you’re not a musician, the technology


surrounds you. ”
Computer-based audio files now can deliver your
favourite songs over the internet. Download a group of
your favourite song as MP3 files and than create a
custom CD to listen to at your next party.

Benefits of the system:

1. Fast standalone audio player.

2. Save user time controlling playback from their mobile doing


anything else.

3. Facility to save play-list files.

4. Made in java, hence is extensible, platform independent,


robust.

Objectives:

The goals of AUDIO PLAYER are:


 Provide a platform to play audio (MP3) file

 Provide different interfaces for different level users

 Support playlist (M3U) file

 Provide playlist management

General Requirements:

The following general requirements were laid out for our project named
AUDIO PLAYER:

 The player can play audiofile.

 The player can provide some necessary function of playing


audio(MP3) file, such as previous, next, random, repeat etc.

 Users can choose their interface for their level.

 Users can add new songs to the playlist or manage their playlist.

 All user’s data and playlists could be stored electronically.


PROBLEM STATEMENT

Portable audio market was shifted from digital

era that audio players became popular.

After digital portable audio players started

popping up, it lost its market to other

companies. It is flexible, adaptable, reliable

and user-friendly. The funded project was an

attempt to come up with innovative content

development and alternative technique

methods for audio player.


CODE DESIGN
In this article, we would like to present a Swing-based
application that is able to play back audio files (in WAV
(*.wav) format) and show you how to build one. This
audio player program will look like this:

The program is working just like a typical audio player.


First, let’s see how this program is supposed to work.
Click the Open button to pick an audio file:
Note that this audio player program is built based on
pure Java Sound API so it can play only *.wav files
(other supported formats are *.aifc, *.aiff, *.au and *.snd
but these are less popular). Select a file in the dialog
then click Open, the program will play back the audio
file:
You can notice that duration of the audio file is shown on
the right most (in form of hour: minute: second). The
current playing time is shown on the left most. During the
playback, the slider is moving gradually from the left to
the right to indicate the progress. Click the Pause button
to temporarily pause the playback:

The slider stops moving and the Pause button’s label


becomes Resume which will continue the playback
when clicked.

Click the Stop button to terminate playing the


audio:
THE PROGRAM CONSIST OF THREE CLASSES:

 AudioPlayer.java:

This is a utility class that provides primary functionalities


for playing back an audio file like play, stop, pause, and
resume. It is based on the Java Sound API. This class is
an enhanced version of the technique discussed in the
tutorial: How to play back audio in Java with examples.
The enhancements are for working in a Swing-based
application. A separate thread should be spawned to use
this utility class.

 PlayingTimer.java:
This thread-based class is responsible to generate
current playing time during the playback. It also updates
the slider accordingly.
 SwingAudioPlayer.java:

This is the main program which is based on a JFrame. It


constructs the user interface and wires
to AudioPlayerand PlayingTimer together to form a nice-
looking and functional audio player program.
It’s not convenient for listing the entire program’s source
code here. So you can study this program by
downloading the below attachment which includes an
executable jar file and full project’s source code. Enjoy!

HARDWARE REQUIREMENTS:

1. A Bluetooth enabled mobile phone with CLDC 1.1 and JSR82


configuration.

2. A typical Bluetooth USB dongle.

3. A computer with minimum following requirements.


Minimum Recommended

Processor 233MHz 300 MHz or higher

Memory 64MB RAM 128 MB RAM or higher

Video adapter
and monitor Super VGA(800 x 600) Super VGA (800 x 600) or
higher resolution

Hard drive disk


free space 1.5GB 1.5 GB or higher

Devices Keyboard and mouse Keyboard and


mouse

Others Sound card,speakers Sound card, speakers

Software Requirements:

Programming language: Java

Java Technology: Swings

Java Version: JDK

Operating System: Windows XP/LINUX


SYSTEM DESIGN

a)DESIGN:
let’s see how this pretty nice program is built. The
following class diagram describes how the program is
designed:
b) ALGORITHM:

STEP 1: Use Swing-Based Application.

STEP 2: Create an object of AudioInputStream


by using AudioSystem.getAudioInputStream.
AudioInputStream converts an audio file into
stream.

STEP 3: Get a clip references object from


AudioSystem.

STEP 4: Stream an audio input stream from


which audio data will be read into the clip by
using open() method of Clip interface.

STEP 5: Set the required properties to the clip


like frame position, loop, microsecond position.

STEP 6: End the clip.


c) FUNCTIONAL FLOWCHART:
SCOPE
 Changing format of media file.

 Playing file backwards with multiple speeds.

 Live broadcast over Internet.

 Zooming in and out video file.

 Supports for capturing media device.

 Cutting the media files into small sub media files.

 Integration with some web browser as plug in.


LIMITATIONS
 It doesn’t support video files.

 No support for custom Skins like winamp or


window media player.

 No support for lyrics.

 No graphic equalizer, for filtering sound.

 No Visualizer.

 Drag and drop facility is not there.


CONCLUSION
Working on this project was quite difficult

as even till date the project is incomplete.

We really enjoyed by working on this

project. We knew at the beginning of this

project that its too ambitious for us, and

chances for its success were very low.

Taking risk helped us to learn faster.

As even we kept this project as open

source, many others will be using our

code so that they can make it better and

complete.

You might also like