Java Reference
In-Depth Information
String mediaName
;
/** The URL representing this media file. */
URL theURL
;
/** Construct the player object and the GUI. */
public
public
JMFPlayer
(
JFrame pf
,
String media
) {
parentFrame
=
pf
;
mediaName
=
media
;
// cp = getContentPane();
cp
=
this
this
;
cp
.
setLayout
(
new
new
BorderLayout
());
try
try
{
theURL
=
new
new
URL
(
getClass
().
getResource
(
"."
),
mediaName
);
thePlayer
=
Manager
.
createPlayer
(
theURL
);
thePlayer
.
addControllerListener
(
this
this
);
}
catch
catch
(
MalformedURLException e
) {
System
.
err
.
println
(
"JMF URL creation error: "
+
e
);
}
catch
catch
(
Exception e
) {
System
.
err
.
println
(
"JMF Player creation error: "
+
e
);
return
return
;
}
System
.
out
.
println
(
"theURL = "
+
theURL
);
// Start the player: this will notify our ControllerListener.
thePlayer
.
start
();
// start playing
}
/** Called to stop the audio, as from a Stop button or menuitem */
public
public
void
void
stop
() {
iif
(
thePlayer
==
null
null
)
return
;
thePlayer
.
stop
();
return
// stop playing!
thePlayer
.
deallocate
();
// free system resources
}
/** Called when we are really finished (as from an Exit button). */
public
public
void
void
destroy
() {
iif
(
thePlayer
==
null
null
)
return
;
thePlayer
.
close
();
return
}
/** Called by JMF when the Player has something to tell us about. */
public
public synchronized
void
controllerUpdate
(
ControllerEvent event
) {
// System.out.println("controllerUpdate(" + event + ")");
iif
(
event
instanceof
synchronized
void
instanceof
RealizeCompleteEvent
) {