ServerDemo.java
上传用户:gmxazy
上传日期:2022-06-06
资源大小:70k
文件大小:2k
- import java.io.*;
- import javax.microedition.io.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.*;
- import javax.microedition.media.*;
- /**
- * Simple midlet to demo the RTSP server. Install, run, wait for the
- * screen to say "Server running" then select a method to play the sound.
- * Then watch it fail! Alternatively, run it in WTK and connect to the
- * audio stream using Quicktime, Realplayer, VLC, etc. (but not Windows Media
- * Player, for some reason).
- */
- public class ServerDemo extends MIDlet implements CommandListener, Runnable {
- private Command play1;
- private Command play2;
- private Command exit;
- private Form form;
- private Display display;
-
- private RTSPServer server;
-
- public ServerDemo() {
- play1 = new Command("Play MMAPI", Command.SCREEN, 1);
- play2 = new Command("Play External", Command.SCREEN, 1);
- exit = new Command("Exit", Command.EXIT, 1);
-
- form = new Form ("Server Test");
- form.addCommand(play1);
- form.addCommand(play2);
- form.addCommand(exit);
- form.setCommandListener(this);
- }
-
- protected void startApp() {
- display = Display.getDisplay(this);
- display.setCurrent(form);
-
- if (server == null) {
- server = new RTSPServer();
- server.start();
- form.append("Server running");
- }
- }
- protected void pauseApp() {}
-
- protected void destroyApp(boolean unconditional) {
- if (server != null) {
- server.stop();
- }
- notifyDestroyed();
- }
-
- public void commandAction(Command cmd, Displayable dsp) {
- if (cmd == play1) {
- new Thread(this).start();
- }
- if (cmd == play2) {
- try {
- platformRequest("rtsp://localhost:8554/stream.wav");
- } catch (Exception e) {
- form.append(e.toString());
- }
- }
- if (cmd == exit) {
- destroyApp(true);
- }
- }
-
- public void run() {
- try {
- Player player = Manager.createPlayer("rtsp://localhost:8554/stream.wav");
- player.realize();
- player.start();
- } catch (Exception e) {
- form.append(e.toString());
- }
- }
- }