Sun Java Solaris Communities My SDN Account Join SDN
 
1.0 Programmers Guide

1.0 Overview

 
TOC  Prev  Next  
In many cases, instead of playing a single media stream from beginning to end, you want to play a portion of the stream or synchronize the playback of multiple streams. The JMF TimeBase and Clock interfaces define the mechanism for managing the timing and synchronization of media playback.

A TimeBase represents the flow of time. A time-base time cannot be transformed or reset. A Java Media Player uses its TimeBase to keep time in the same way that a quartz watch uses a crystal that vibrates at a known frequency to keep time. The system maintains a master TimeBase that measures time in nanoseconds from a specified base time, such as January 1, 1970. The system TimeBase is driven by the system clock and is accessible through the Manager.getSystemTimeBase method.

A Player's media time represents a point in time within the stream that the Player is presenting. The media time can be started, stopped, and reset much like a stopwatch.

A Clock defines the mapping between a TimeBase and the media time.

A Java Media Player can answer several timing queries about the media source it is presenting. Of course, timing information is subject to the physical characteristics and limitations of both the media source and of the network device on which it is stored.

A Time object represents a quantity of some time unit, such as nanoseconds. You use Time objects when you query or set a Player's timing information.

6.1 Setting the Media Time

Setting a Player's media time is equivalent to setting a read position within a media stream. For a media data source such as a file, the media time is bounded; the maximum media time is defined by the end of the media stream.

To set the media time you call setMediaTime and pass in a Time object that represents the time you want to set.

6.2 Getting the Current Time

Calling getMediaTime returns a Time object that represents the Player's current media time. If the Player is not presenting media data, this is the point from which media presentation will commence. There is not a one-to-one correspondence between a media time and a particular frame. Each frame is presented for a certain period of time, and the media time continues to advance during that period.

For example, imagine you have a slide show Player that displays each slide for 5 seconds-the Player essentially has a frame rate of 0.2 frames per second.

If you start the Player at time 0.0, while the first frame is displayed, the media time advances from 0.0 to 5.0. If you start at time 2.0, the first frame is displayed for 3 seconds, until time 5.0 is reached.

You can get a Player's current time-base time by getting the Player's TimeBase and calling getRefTime:

myCurrentTBTime = player1.getTimeBase().getRefTime();
When a Player is running, you can get the time-base time that corresponds to a particular media time by calling mapToTimeBase.

6.3 Setting a Player's Rate

The Player's rate determines how media time changes with respect to time-base time; it defines how many units a Player's media time advances for every unit of time-base time. The Player's rate can be thought of as a temporal scale factor. For example, a rate of 2.0 indicates that media time passes twice as fast as the time-base time when the Player is started.

In theory, a Player's rate could be set to any real number, with negative rates interpreted as playing the media in reverse. However, some media formats have dependencies between frames that make it impossible or impractical to play them in reverse or at non-standard rates.

When setRate is called on a Player, the method returns the rate that is actually set, even if it has not changed. Players are only guaranteed to support a rate of 1.0.

6.4 Getting a Player's Duration

Since your program might need to determine how long a given media stream will run, all Controllers implement the Duration interface. This interface comprises a single method, getDuration. Duration represents the length of time that a media object would run, if played at the default rate of 1.0. A media stream's duration is accessible only through the Player.

If the duration can't be determined when getDuration is called, DURATION_UNKNOWN is returned. This can happen if the Player has not yet reached a state where the duration of the media source is available. At a later time, the duration might be available and a call to getDuration would return the duration value. If the media source does not have a defined duration, as in the case of a live broadcast, getDuration returns DURATION_UNBOUNDED.

TOC  Prev  Next