MP3 Lab

foreheadsobstinacySoftware and s/w Development

Aug 15, 2012 (4 years and 10 months ago)

253 views

CSC1030

Hands
-
on Introduction to Java

200
9
-
20
10

Second

Term

Department of Computer Science and Engineering

The Chinese University of Hong Kong


Copyright © 2002
-
20
10

By Michael Ping
-
Fu, Fung


Page
1

of
2



Lab

Exercise: MP3Player




Aim:

1.
Using existing classes and objects
.



2.
Learning MP3 file playing
.


Flow and Procedure
:


1.

Have you own
headphone
s
/ headset
s
/ speakers

ready.


Make sure
your computer

sounds.


2.

Download, u
n
zip and open the given NetBeans P
roject
MP3Player
. Try running it.


3.

Change the program a little bit: try playing
the MP3 files in the folder
DTMF_DialTone
\
.


4.

Change the program a little bit: try playing some other MP3 files in the web page
http://www.archive.org/details/solo
-
piano
-
7#ff2

(scroll to the last table
of the page for a list)
directly
, i
.e. without downloading and saving the MP3 files.


5.

Try playing a local file using
playURL(
"file://localhost/D:/xy
\
\
pq/a.mp3"
)
.


6.

Ch
ange the program a little bit: try playing a non
-
exist or invalid local file. Observe the error
messages.


7.

Change the program a little bit: try playing an invalid URL address. Observe the error
messages.


8.

In the NetBeans Navigator Window (Ctrl
-
7)


Membe
r view, move the mouse pointer over a
method. Stop there and wait for the documentation to show. What do you observe? How can
you change/ update the documentation?


9.

Create a new method
,

say
:


public
String concatenate(String s1, byte n, String s2)

{


return "result";

}

Type
/**
<Enter>

right above the method declaration ( ). See what appears.


Explanation
:


1.

File and network operations (in general Input and Output (I/O) operations) are error
-
prone and
risky. Such operations may fail our program
s. If we refrain from handling such error
situations, our I/O related methods (as well as the involved message senders) should declare

throws Exception

. This is a Java language requirement.

We will discuss this later.


2.

JLayer

Java library package prov
ides MP3 playing capabilities. We can simply create an
AdvancedPlayer

object with a file or network input stream, then we can play a MP3 easily.


3.

Creating a
FileInputStream

object
is easy
.

Creating an
InputStream

object
from an
URL is also easy.

Copyright © 2002
-
20
10

By Michael Ping
-
Fu, Fung


Page
2

of
2


Concept

to be discussed in the future:
FileInputStream

is

a
kind

of
InputStream
,

i.e. sub
-
set and super
-
set relationship. In Java, class type
FileInputStream

is

a subclass
of type
InputStream
. BTW, this is NOT related to this lab.


4.

Block comment
/**

provides u
s a
n

easy way to write/ generate documentation at the time we
write our code. Click NetBeans Menu Build


Gene
r
ate JavaDoc,
and

find how powerful it is!


5.

Locate your NetBeans Project folder
MP3Player
\
. Explore the sub
-
folder
dist
\

(means
distribution.)
Double click on
MP3Player.jar
. What happens? Yes, your MP3Player has
been packaged for distribution. Check also the
javadoc
\

sub
-
folder. Exciting?!


6.

If you insist typing commands to try our Sample Program, here you are:


folder
dist
\
>
java
-
classpath
l
ib
\
jl1.0.1.jar

-
jar
MP3Player.jar


folder
build
\
classes
\
>
java
-
classpath
..
\
..
\
jl1.0.1.jar
;
.

MP3Player


You have been warned: this is tricky and not for beginners. It involves relative paths.


Note about
our
Lab
:


1.

You have nothing to submit in this Lab.


2.

We have prepared a
sample program

for you to
try.


3.

Note that this
exercise
should be done under
Windows/
NetBeans.


4.

JLayer is a third party API.