streamingdatasource.java

来自「一个j2me编写的手机播放 rtsp协议传输流媒体文件的例子」· Java 代码 · 共 91 行

JAVA
91
字号
import java.io.IOException;
import javax.microedition.media.Control;
import javax.microedition.media.protocol.DataSource;
import javax.microedition.media.protocol.SourceStream;

public class StreamingDataSource extends DataSource {

  // the full URL like locator to the destination
  private String locator;

  // the internal streams that connect to the source
  // in this case, there is only one
  private SourceStream[] streams;

  // is this connected to its source?
  private boolean connected = false;

  public StreamingDataSource(String locator) {
	  super(locator);
	  setLocator(locator);
  }

  public void setLocator(String locator) { this.locator = locator; }

  public String getLocator() { return locator; }

  public void connect() throws IOException {

		// if already connected, return
		if (connected) return;

		// if locator is null, then can't actually connect
		if (locator == null)
			throw new IOException("locator is null");

		// now populate the sourcestream array
		streams = new RTPSourceStream[1];

		// with a new RTPSourceStream
		streams[0] = new RTPSourceStream(locator);

		// set flag
		connected = true;

	}

  public void disconnect() {

    // if there are any streams
    if (streams != null) {

      // close the individual stream
			try {
				((RTPSourceStream)streams[0]).close();
			} catch(IOException ioex) {} // silent
    }

    // and set the flag
    connected = false;
	}

  public void start() throws IOException {

		if(!connected) return;

		// start the underlying stream
		((RTPSourceStream)streams[0]).start();

	}

  public void stop() throws IOException {

		if(!connected) return;

	  // stop the underlying stream
	  ((RTPSourceStream)streams[0]).close();

	}

  public String getContentType() {
		// for the purposes of this article, it is only video/mpeg
		return "video/mpeg";
	}

  public Control[] getControls() { return new Control[0]; }

  public Control getControl(String controlType) { return null; }

  public SourceStream[] getStreams() {	return streams; }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?