📄 player.java
字号:
* Value 300 is assigned to <code>PREFETCHED</code>. */ int PREFETCHED = 300; /** * The state of the <code>Player</code> indicating that the * <code>Player</code> has already started. * <p> * Value 400 is assigned to <code>STARTED</code>. */ int STARTED = 400; /** * The state of the <code>Player</code> indicating that the * <code>Player</code> is closed. * <p> * Value 0 is assigned to <code>CLOSED</code>. */ int CLOSED = 0; /** * The returned value indicating that the requested time is unknown. * <p> * Value -1 is assigned to <code>TIME_UNKNOWN</code>. */ long TIME_UNKNOWN = -1; /** * Constructs portions of the <code>Player</code> without * acquiring the scarce and exclusive resources. * This may include examining media data and may * take some time to complete. * <p> * When <code>realize</code> completes successfully, * the <code>Player</code> is in the * <i>REALIZED</i> state. * <p> * If <code>realize</code> is called when the <code>Player</code> is in * the <i>REALIZED</i>, <i>PREFETCHTED</i> or <i>STARTED</i> state, * the request will be ignored. * * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @exception MediaException Thrown if the <code>Player</code> cannot * be realized. * @exception SecurityException Thrown if the caller does not * have security permission to realize the <code>Player</code>. * */ void realize() throws MediaException; /** * Acquires the scarce and exclusive resources * and processes as much data as necessary * to reduce the start latency. * <p> * When <code>prefetch</code> completes successfully, * the <code>Player</code> is in * the <i>PREFETCHED</i> state. * <p> * If <code>prefetch</code> is called when the <code>Player</code> * is in the <i>UNREALIZED</i> state, * it will implicitly call <code>realize</code>. * <p> * If <code>prefetch</code> is called when the <code>Player</code> * is already in the <i>PREFETCHED</i> state, the <code>Player</code> * may still process data necessary to reduce the start * latency. This is to guarantee that start latency can * be maintained at a minimum. * <p> * If <code>prefetch</code> is called when the <code>Player</code> * is in the <i>STARTED</i> state, * the request will be ignored. * <p> * If the <code>Player</code> cannot obtain all * of the resources it needs, it throws a <code>MediaException</code>. * When that happens, the <code>Player</code> will not be able to * start. However, <code>prefetch</code> may be called again when * the needed resource is later released perhaps by another * <code>Player</code> or application. * * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @exception MediaException Thrown if the <code>Player</code> cannot * be prefetched. * @exception SecurityException Thrown if the caller does not * have security permission to prefetch the <code>Player</code>. * */ void prefetch() throws MediaException; /** * Starts the <code>Player</code> as soon as possible. * If the <code>Player</code> was previously stopped * by calling <code>stop</code>, * it will resume playback * from where it was previously stopped. If the * <code>Player</code> has reached the end of media, * calling <code>start</code> will automatically * start the playback from the start of the media. * <p> * When <code>start</code> returns successfully, * the <code>Player</code> must have been started and * a <code>STARTED</code> event will * be delivered to the registered <code>PlayerListener</code>s. * However, the <code>Player</code> is not guaranteed to be in * the <i>STARTED</i> state. The <code>Player</code> may have * already stopped (in the <i>PREFETCHED</i> state) because * the media has 0 or a very short duration. * <p> * If <code>start</code> is called when the <code>Player</code> * is in the <i>UNREALIZED</i> or <i>REALIZED</i> state, * it will implicitly call <code>prefetch</code>. * <p> * If <code>start</code> is called when the <code>Player</code> * is in the <i>STARTED</i> state, * the request will be ignored. * * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @exception MediaException Thrown if the <code>Player</code> cannot * be started. * @exception SecurityException Thrown if the caller does not * have security permission to start the <code>Player</code>. */ void start() throws MediaException; /** * Stops the <code>Player</code>. It will pause the playback at * the current media time. * <p> * When <code>stop</code> returns, the <code>Player</code> is in the * <i>PREFETCHED</i> state. * A <code>STOPPED</code> event will be delivered to the registered * <code>PlayerListener</code>s. * <p> * If <code>stop</code> is called on * a stopped <code>Player</code>, the request is ignored. * * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @exception MediaException Thrown if the <code>Player</code> * cannot be stopped. */ void stop() throws MediaException; /** * Release the scarce or exclusive * resources like the audio device acquired by the <code>Player</code>. * <p> * When <code>deallocate</code> returns, the <code>Player</code> * is in the <i>UNREALIZED</i> or <i>REALIZED</i> state. * <p> * If the <code>Player</code> is blocked at * the <code>realize</code> call while realizing, calling * <code>deallocate</code> unblocks the <code>realize</code> call and * returns the <code>Player</code> to the <i>UNREALIZED</i> state. * Otherwise, calling <code>deallocate</code> returns the * <code>Player</code> to the <i>REALIZED</i> state. * <p> * If <code>deallocate</code> is called when the <code>Player</code> * is in the <i>UNREALIZED</i> or <i>REALIZED</i> * state, the request is ignored. * <p> * If the <code>Player</code> is <code>STARTED</code> * when <code>deallocate</code> is called, <code>deallocate</code> * will implicitly call <code>stop</code> on the <code>Player</code>. * * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. */ void deallocate(); /** * Close the <code>Player</code> and release its resources. * <p> * When the method returns, the <code>Player</code> is in the * <i>CLOSED</i> state and can no longer be used. * A <code>CLOSED</code> event will be delivered to the registered * <code>PlayerListener</code>s. * <p> * If <code>close</code> is called on a closed <code>Player</code> * the request is ignored. */ void close(); /** * Sets the <code>Player</code>'s <i>media time</i>. * <p> * For some media types, setting the media time may not be very * accurate. The returned value will indicate the * actual media time set. * <p> * Setting the media time to negative values will effectively * set the media time to zero. Setting the media time to * beyond the duration of the media will set the time to * the end of media. * <p> * There are some media types that cannot support the setting * of media time. Calling <code>setMediaTime</code> will throw * a <code>MediaException</code> in those cases. * * @param now The new media time in microseconds. * @return The actual media time set in microseconds. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>UNREALIZED</i> or <i>CLOSED</i> state. * @exception MediaException Thrown if the media time * cannot be set. * @see #getMediaTime */ long setMediaTime(long now) throws MediaException; /** * Gets this <code>Player</code>'s current <i>media time</i>. * If the <i>media time</i> cannot be determined, * <code>getMediaTime</code> returns <code>TIME_UNKNOWN</code>. * * @return The current <i>media time</i> in microseconds or * <code>TIME_UNKNOWN</code>. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @see #setMediaTime */ long getMediaTime(); /** * Gets the current state of this <code>Player</code>. * The possible states are: <i>UNREALIZED</i>, * <i>REALIZED</i>, <i>PREFETCHED</i>, <i>STARTED</i>, <i>CLOSED</i>. * * @return The <code>Player</code>'s current state. */ int getState(); /** * Get the duration of the media. * The value returned is the media's duration * when played at the default rate. * <br> * If the duration cannot be determined (for example, the * <code>Player</code> is presenting live * media) <CODE>getDuration</CODE> returns <CODE>TIME_UNKNOWN</CODE>. * * @return The duration in microseconds or <code>TIME_UNKNOWN</code>. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. */ long getDuration(); /** * Get the content type of the media that's * being played back by this <code>Player</code>. * <p> * See <a href="Manager.html#content-type">content type</a> * for the syntax of the content type returned. * * @return The content type being played back by this * <code>Player</code>. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>UNREALIZED</i> or <i>CLOSED</i> state. */ String getContentType(); /** * Set the number of times the <code>Player</code> will loop * and play the content. * <p> * By default, the loop count is one. That is, once started, * the <code>Player</code> will start playing from the current * media time to the end of media once. * <p> * If the loop count is set to N where N is bigger than one, * starting the <code>Player</code> will start playing the * content from the current media time to the end of media. * It will then loop back to the beginning of the content * (media time zero) and play till the end of the media. * The number of times it will loop to the beginning and * play to the end of media will be N-1. * <p> * Setting the loop count to 0 is invalid. An * <code>IllegalArgumentException</code> will be thrown. * <p> * Setting the loop count to -1 will loop and play the content * indefinitely. * <p> * If the <code>Player</code> is stopped before the preset loop * count is reached either because <code>stop</code> is called, * calling <code>start</code> again will * resume the looping playback from where it was stopped until it * fully reaches the preset loop count. * <p> * An <i>END_OF_MEDIA</i> event will be posted * every time the <code>Player</code> reaches the end of media. * If the <code>Player</code> loops back to the beginning and * starts playing again because it has not completed the loop * count, a <i>STARTED</i> event will be posted. * * @param count indicates the number of times the content will be * played. 1 is the default. 0 is invalid. -1 indicates looping * indefintely. * @exception IllegalArgumentException Thrown if the given * count is invalid. * @exception IllegalStateException Thrown if the * <code>Player</code> is in the <i>STARTED</i> * or <i>CLOSED</i> state. */ void setLoopCount(int count); /** * Add a player listener for this player. * * @param playerListener the listener to add. * If <code>null</code> is used, the request will be ignored. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @see #removePlayerListener */ void addPlayerListener(PlayerListener playerListener); /** * Remove a player listener for this player. * * @param playerListener the listener to remove. * If <code>null</code> is used or the given * <code>playerListener</code> is not a listener for this * <code>Player</code>, the request will be ignored. * @exception IllegalStateException Thrown if the <code>Player</code> * is in the <i>CLOSED</i> state. * @see #addPlayerListener */ void removePlayerListener(PlayerListener playerListener);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -