|
QTJPlayer 1.0.2 beta | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
de.muntjak.qtjplayer.QTJPlayer
public class QTJPlayer
QTJPlayer is a visual component to display and control QuickTime media (referred
to as movies, though media can also be images, sounds or text files).
It can be used as a simple media player or it can be integrated
into a graphical UI. By default, the player provides controls to
let the user define a play list, start, pause and stop movies, set volume, etc.
You can hide the controls and control media from application
code (or create controls of your own).
QTJPlayer consists of four components:
setShowMenuBar(boolean)
).
setShowMovieControllers(boolean)
).
setShowPlayList(boolean)
).
setMovie(File)
(this will load the media, then calling playMovie
starts
playing the media) or you can specify a play list.
Play list related methods are:
setPlayList(File[])
providing one ore more media files.
clearPlayList
.
addMovie(File)
or insert
an entry using addMovie(int, File)
.
removeMovie(int)
.
setSelectedMovie(int)
.
setLoopPlayList(boolean)
.
setMoviePanelSize(Dimension)
). If the
movie is larger than the display area, it will be scaled to fit inside,
if it is smaller than the display area, it will be centered.
playMovie()
.
pauseMovie()
.
stopMovie()
.
setMovieVolume(float)
.
setLoopMovie(boolean)
.
getMovieDuration
.
getMovieTime
and
setMovieTime(int)
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
DOUBLE_SIZE
Movie size constant: display media at double size |
static int |
HALF_SIZE
Movie size constant: display media at half size |
static int |
NORMAL_SIZE
Movie size constant: display media at normal size |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
QTJPlayer()
Constructs the UI after checking for QuickTime for Java 6.1 or later being installed. |
Method Summary | |
---|---|
void |
addMovie(File mediaFile)
Appends the specified media to the end of the play list. |
void |
addMovie(int index,
File mediaFile)
Inserts the specified media in the play list at the specified index. |
void |
addMovieListener(MovieListener listener)
Adds a MovieListener . |
void |
clearPlayList()
Clears the play list after stopping the currently playing movie. |
protected void |
fireMovieLoaded()
Forwards the appropriate MovieEvent to the movieLoaded
method of all registered listeners. |
protected void |
fireMoviePaused()
Forwards the appropriate MovieEvent to the moviePaused
method of all registered listeners. |
protected void |
fireMovieStarted()
Forwards the appropriate MovieEvent to the movieStarted
method of all registered listeners. |
protected void |
fireMovieStopped()
Forwards the appropriate MovieEvent to the movieStopped
method of all registered listeners. |
int |
getMovieDuration()
Returns the currently selected media's duration. |
Dimension |
getMovieOriginalSize()
Returns the currently selected media's original size or null if no media is currently selected. |
Dimension |
getMoviePanelSize()
Returns the size of the movie display area. |
int |
getMoviesSize()
Returns all movies' current display size, one of QTJPlayer.HALF_SIZE ,
QTJPlayer.NORMAL_SIZE or
QTJPlayer.DOUBLE_SIZE . |
int |
getMovieTime()
Returns the selected media's current time. |
float |
getMovieVolume()
Returns the current movie volume represented as a float value between 0.0 and 1.0. |
File[] |
getPlayList()
Returns a copy of the play list as an array of File objects. |
int |
getPlayListSize()
Returns the play list's current size. |
int |
getSelectedMovie()
Returns the currently selected movie's index or -1 if the play list is empty. |
int |
getUnitsPerSecond()
Returns the currently selected media's time scale. |
boolean |
isLoopMovie()
Returns the current movie's loop state. |
boolean |
isLoopPlayList()
Returns the play list's loop state. |
boolean |
isProcessKeyEvents()
Returns true if key events are processed,
false otherwise. |
boolean |
isShowMenuBar()
Returns the showMenuBar property. |
boolean |
isShowMovieControllers()
Returns whether movie controllers are currently displayed. |
boolean |
isShowPlayList()
Returns whether the play list is currently displayed. |
static void |
main(String[] args)
You can start QTJPlayer as a simple QickTime media player by executing > java -jar qtjplayer.jar from the command line. |
void |
pauseMovie()
Pauses the currently playing media. |
void |
playMovie()
Starts playing the media currently selected in the play list, respectively the first media of the play list if no play list entry is currently selected. |
void |
readExternal(ObjectInput in)
Restores all public properties. |
void |
removeMovie(int index)
Removes the specified entry from the play list. |
void |
removeMovieListener(MovieListener listener)
Removes a MovieListener . |
void |
setBackground(Color bg)
Sets the background color of the menu bar, the movie panel and the play list panel. |
void |
setLoopMovie(boolean b)
Enables or disables looping the currently playing / selected movie. |
void |
setLoopPlayList(boolean b)
Sets the play list's loop state. |
void |
setMovie(File mediaFile)
Loads the specified media so it is ready for playing. |
void |
setMoviePanelSize(Dimension size)
Sets the size of the movie display area. |
void |
setMoviesSize(int size)
Sets the display size of all movies. |
void |
setMovieTime(int time)
Sets the the currently selected media's new time. |
void |
setMovieVolume(float volume)
Sets the movie volume to the specified value. |
void |
setPlayList(File[] mediaFiles)
Sets a new play list from the given array. |
void |
setProcessKeyEvents(boolean b)
Sets if this component should process key events if it has the keyboard focus. |
void |
setSelectedMovie(int index)
Selects a movie specified by its index in the play list. |
void |
setShowMenuBar(boolean showMenuBar)
Hides or shows the menubar dependent on the given flag. |
void |
setShowMovieControllers(boolean showControllers)
Hides or shows the movie controllers. |
void |
setShowPlayList(boolean showPlayList)
Hides or shows the play list dependent on the given flag. |
void |
showMovieInfo()
Displays information about the currently selected movie (such as its frame rate and duration) using a non-modal dialog. |
void |
stopMovie()
Stops the currently playing media. |
void |
writeExternal(ObjectOutput out)
Writes all public properties. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int HALF_SIZE
public static final int NORMAL_SIZE
public static final int DOUBLE_SIZE
Constructor Detail |
---|
public QTJPlayer()
Method Detail |
---|
public void addMovieListener(MovieListener listener)
MovieListener
. The listener will receive
events if a movie gets loaded, started, paused or stopped.
listener
- the MovieListener
to addpublic void removeMovieListener(MovieListener listener)
MovieListener
.
listener
- the MovieListener
to removeprotected void fireMovieLoaded()
MovieEvent
to the movieLoaded
method of all registered listeners.
protected void fireMovieStarted()
MovieEvent
to the movieStarted
method of all registered listeners.
protected void fireMovieStopped()
MovieEvent
to the movieStopped
method of all registered listeners.
protected void fireMoviePaused()
MovieEvent
to the moviePaused
method of all registered listeners.
public boolean isShowMovieControllers()
true
if the movie controllers
are currently displayed, false
otherwisepublic void setShowMovieControllers(boolean showControllers)
true
.
showControllers
- the new valuepublic boolean isLoopMovie()
public void setLoopMovie(boolean b)
false
.
b
- the new valuepublic boolean isLoopPlayList()
public void setLoopPlayList(boolean b)
true
, the
first entry of the play list will start playing as soon as
the last entry has ended. The default value of this property
is false
.
b
- the new loop statepublic boolean isShowPlayList()
true
if the play list is currently displayed.
false
otherwisepublic void setShowPlayList(boolean showPlayList)
true
.
showPlayList
- the new valuepublic boolean isShowMenuBar()
showMenuBar
property.
showMenuBar
propertypublic void setShowMenuBar(boolean showMenuBar)
true
.
showMenuBar
- the new valuepublic void setBackground(Color bg)
setBackground
in class JComponent
public void stopMovie()
public void pauseMovie()
User gestures: By double-clicking inside the movie display area or by pressing Enter, media can be started and paused.
public void playMovie()
User gestures: By double-clicking inside the movie display area or by pressing Enter, media can be started and paused.
public boolean isProcessKeyEvents()
true
if key events are processed,
false
otherwise.
true
if key events are processed,
false
otherwisesetProcessKeyEvents(boolean)
public void setProcessKeyEvents(boolean b)
true
,
the following key events will be processed:
Enter
: play / pause media
Cursor_Right
: Fast forward
Cursor_Left
: Fast backward
Ctrl+O
: Open play list
Ctrl+S
: Save play list
Ctrl+0
: Display media at half size
Ctrl+1
: Display media at normal size
Ctrl+2
: Display media at double size
Ctrl+L
: Switch media loop mode
Ctrl+I
: Show media info
F1
: Display help information
true
.
Note: If Beans.isDesignTime()
returns true
,
QTJPlayer will ignore key presses and setting this property will have
no effect.
b
- if true
, key events will be processed,
if false
, key presses will be ignoredpublic Dimension getMovieOriginalSize()
null
if no media is currently selected.
For pure audio or midi, the returned Dimension will be
of zero width and height.
null
if no media is currently selectedpublic int getMoviesSize()
QTJPlayer.HALF_SIZE
,
QTJPlayer.NORMAL_SIZE
or
QTJPlayer.DOUBLE_SIZE
.
public void setMoviesSize(int size)
Note: Because this also affects QTJPlayer's preferred size, the component might shrink or grow, dependent on the kind of layout it was added to.
size
- one of
QTJPlayer.HALF_SIZE
,
QTJPlayer.NORMAL_SIZE
or
QTJPlayer.DOUBLE_SIZE
QTJPlayer.NORMAL_SIZE
will be selectedpublic static void main(String[] args)
> java -jar qtjplayer.jar
args
- ignoredpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public Dimension getMoviePanelSize()
setMoviePanelSize(Dimension)
public void setMoviePanelSize(Dimension size)
Dimension(320, 240)
.
size
- the new movie display area sizepublic void clearPlayList()
public int getUnitsPerSecond()
getMovieDuration() / getUnitsPerSecond()
.
public int getMovieDuration()
getMovieDuration() / getUnitsPerSecond()
.
public int getMovieTime()
getMovieTime,
getMovieDuration and getUnitsPerSecond
.
- Returns:
- the selected media's current time
- See Also:
getMovieDuration()
,
setMovieTime(int)
public void setMovieTime(int time)
time
- the new time valuegetMovieTime()
,
getMovieDuration()
public void setMovie(File mediaFile)
null
, the
play list is cleared.
If some movie is currently playing, it is stopped and
the specified movie starts playing.
mediaFile
- a media filepublic float getMovieVolume()
public void setMovieVolume(float volume)
volume
- the new valuepublic void showMovieInfo()
public File[] getPlayList()
File
objects.
File
objectspublic void setPlayList(File[] mediaFiles)
null, the play list is cleared.
If some movie is currently playing, it is stopped.
The first entry of the new play list will be loaded and
is ready to be played.
- Parameters:
mediaFiles
- array of File
objects, which may be
empty
public int getPlayListSize()
public int getSelectedMovie()
setSelectedMovie(int)
public void setSelectedMovie(int index)
index
- an index into the play listpublic void addMovie(File mediaFile)
mediaFile
- a media filepublic void addMovie(int index, File mediaFile)
index
is outside the play list
range, it will be corrected so the specified media will
either be appended to the play list or will be inserted
at the first position.
index
- an index into the play listmediaFile
- a media filepublic void removeMovie(int index)
index
- the play list index of the media to remove
|
QTJPlayer 1.0.2 beta | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |