⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audiopanel.java

📁 JMS编写的声音播放软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               supported = tracks[i].getSupportedFormats();//将支持的format类型设为第一个               if (supported.length > 0) {               chosen = supported[0];               //将传输数据量设为最小用G723/rtp格式                   tracks[i].setFormat(audioFormat);                   atLeastOneTrack = true;               } else                   tracks[i].setEnabled(false);           } else               tracks[i].setEnabled(false);       }       if (!atLeastOneTrack)           return "Couldn't set any of the tracks to a valid RTP format";       result = waitForState(processor, Controller.Realized);       if (result == false)           return "Couldn't realize processor";       dataOutput = processor.getDataOutput();       processor.start();       return null;   }   private Integer stateLock = new Integer(0);   private boolean failed = false;  private BorderLayout borderLayout1 = new BorderLayout();   Integer getStateLock() {       return stateLock;   }   void setFailed() {       failed = true;   }   private synchronized boolean waitForState(Processor p, int state) {       p.addControllerListener(new StateListener());       failed = false;       if (state == Processor.Configured) {           p.configure();       } else if (state == Processor.Realized) {           p.realize();       }       while (p.getState() < state && !failed) {           synchronized (getStateLock()) {               try {                   getStateLock().wait();               } catch (InterruptedException ie) {                   return false;               }           }       }       if (failed)           return false;       else           return true;   }   public void transferData(PushBufferStream pbs) {               try{               Data data;               Vector dataVector=new Vector();               Buffer databuf=new Buffer();               pbs.read(databuf);               byte[] databyte=(byte[])databuf.getData();               String ss="start";               dataVector.addElement(databyte);               dataVector.addElement(ss);               data =new Data(dataVector);               channel.sendToAll(client,data);               }catch(Exception ee){                 System.out.println("发送数据错误1:"+ee);                 System.out.println(ee.getMessage());                }   }   class StateListener implements ControllerListener {       public void controllerUpdate(ControllerEvent ce) {           if (ce instanceof ControllerClosedEvent)               setFailed();           if (ce instanceof ControllerEvent) {               synchronized (getStateLock()) {                   getStateLock().notifyAll();               }           }       }   }   class LiveStream implements PushBufferStream, Runnable {      protected ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW);      protected int maxDataLength;      protected byte [] data;      protected Dimension size;      protected RGBFormat rgbFormat;      protected boolean started;      public   Thread mythread;      protected float frameRate = 20f;      protected BufferTransferHandler transferHandler;      protected Control [] controls = new Control[0];//    protected Buffer audioBuffer=new Buffer();      protected boolean videoData = false;      public LiveStream() {              maxDataLength = 1000;      }      public ContentDescriptor getContentDescriptor() {          return cd;      }      public long getContentLength() {          return LENGTH_UNKNOWN;      }      public boolean endOfStream() {          return false;      }      public Format getFormat() {              return audioFormat;      }      public void read(Buffer buffer) {          if(bufdata.size()>1){          synchronized (this) {          try{//	System.out.println("读数据read()");          buffer.setData((byte[])(bufdata.firstElement()));          bufdata.removeElementAt(0);//          System.out.println("bufdata的大小"+bufdata.size());          buffer.setFormat(audioFormat);          buffer.setSequenceNumber(seqnum);          buffer.setLength(bufferlength);          System.out.println("bufdata里面的元素数据个数-1:"+bufdata.size());          }catch(Exception ee){                  System.out.println("error:"+ee);                  System.out.println(ee.getMessage());  }          }      }      }      public void setTransferHandler(BufferTransferHandler transferHandler) {          synchronized (this) {              this.transferHandler = transferHandler;              notifyAll();          }      }      void start(boolean started) {          synchronized ( this ) {              this.started = started;              System.out.println("ready to start thread");              if (started) {                      System.out.println("进入判断语句");                  mythread = new Thread(this);                  mythread.start();                  System.out.println("thread started");              }              notifyAll();          }      }      public void run() {          while (started) {//	    synchronized (this) {//		while (transferHandler == null && started) {//		    try {//			wait(1000);//		    } catch (InterruptedException ie) {//		    }//		} // while//	    }              if (started && transferHandler != null) {                  transferHandler.transferData(this);                  try {                      Thread.currentThread().sleep(600);                  } catch (InterruptedException ise) {                  }              }          } // while (started)      } // run      // Controls      public void ableread(){          transferHandler.transferData(this);          }      public Object [] getControls() {          return controls;      }      public Object getControl(String controlType) {         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;         }      }   }   class dataSource extends PushBufferDataSource {      protected Object [] controls = new Object[0];      protected boolean started = false;      protected String contentType = "raw";      protected boolean connected = false;      protected Time duration = DURATION_UNKNOWN;      protected LiveStream [] streams = null;      protected LiveStream stream = null;      public dataSource() {      }      public String getContentType() {          if (!connected){              System.err.println("Error: dataSource not connected");              return null;          }          return contentType;      }      public void connect() throws IOException {           if (connected)              return;           connected = true;      }      public void disconnect() {          try {              if (started)                  stop();          } catch (IOException e) {}          connected = false;      }      public void start() throws IOException {          // we need to throw error if connect() has not been called          if (!connected)              throw new java.lang.Error("dataSource must be connected before it can be started");          if (started)              return;          started = true;          stream.start(true);      }      public void stop() throws IOException {          if ((!connected) || (!started))              return;          started = false;          stream.start(false);      }      public Object [] getControls() {          return controls;      }      public Object getControl(String controlType) {         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 Time getDuration() {          return duration;      }      public PushBufferStream [] getStreams() {          if (streams == null) {              streams = new LiveStream[1];              stream = streams[0] = new LiveStream();          }          return streams;      }  }}

⌨️ 快捷键说明

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