FileDocCategorySizeDatePackage
MergingDataSource.javaAPI DocJMF 2.1.1e4306Mon May 12 12:21:04 BST 2003com.ibm.media.protocol

MergingDataSource

public class MergingDataSource extends DataSource

Fields Summary
DataSource[]
sources
SourceStream[]
streams
Object[]
controls
Constructors Summary
MergingDataSource(DataSource[] sources)
Constructor


    
       
    

    this.sources = sources;
  
Methods Summary
public voidconnect()


    for (int i = 0; i < sources.length; i++)
      sources[i].connect();
  
public voiddisconnect()


    for (int i = 0; i < sources.length; i++)
      sources[i].disconnect();
  
public java.lang.StringgetContentType()
Returns the content-type of the merged streams. If all streams are RAW, the returned content-type is RAW. Otherwise, the return content-type is MIXED.

    
      if (sources.length == 1)
	  return sources[0].getContentType();

    boolean isRaw = true;

    for (int index = 0; index < sources.length; index++) {
      if (!sources[index].getContentType().equals(ContentDescriptor.RAW)) {
	isRaw = false;
	break;
      }
    }
     
    if (isRaw)
      return ContentDescriptor.RAW;
    else if (sources.length == 1)
      return sources[0].getContentType();
    else
      return ContentDescriptor.MIXED;
  
public java.lang.ObjectgetControl(java.lang.String controlType)
Obtain the object that implements the specified Class or Interface The full class or interface name must be used.

If the control is not supported then null is returned.

return
the object that implements the control, or null.

      try {
          Class  cls = Class.forName(controlType);
          Object cs[] = getControls();
          for (int i = 0; i < cs.length; i++) {
	      if (cls.isInstance(cs[i]))
		  return cs[i];
          }
          return null;
	  
      } catch (Exception e) {   // no such controlType or such control
	  return null;
      }      
  
public java.lang.Object[]getControls()
Obtain the collection of objects that control the object that implements this interface.

If no controls are supported, a zero length array is returned.

return
the collection of object controls

      if (controls == null) {
	  Vector vcontrols = new Vector(1);
	  for (int i = 0; i < sources.length; i++) {
	      Object [] cs = (Object[]) sources[i].getControls();
	      if (cs.length > 0) {
		  for (int j = 0; j < cs.length; j++) {
		      vcontrols.addElement(cs[j]);
		  }
	      }
	  }
	  controls = new Object[vcontrols.size()];
	  for (int c = 0; c < vcontrols.size(); c++)
	      controls[c] = vcontrols.elementAt(c);
      }
	  
      return controls;
  
public javax.media.TimegetDuration()
Get the duration of the media represented by this object. The value returned is the media's duration when played at the default rate. If the duration can't be determined (for example, the media object is presenting live video) getDuration returns DURATION_UNKNOWN.

return
A Time object representing the duration or DURATION_UNKNOWN.

    
    Time longest = new Time(0);

    for (int i = 0; i < sources.length; i++) {
      Time sourceDuration = sources[i].getDuration();
      if (sourceDuration.getSeconds() > longest.getSeconds())
	longest = sourceDuration;
    }

    return longest;
  
public voidstart()

    
    for (int i = 0; i < sources.length; i++)
      sources[i].start();
  
public voidstop()

    
    for (int i = 0; i < sources.length; i++)
      sources[i].stop();