?? chatconsumer.java
字號:
package audiopanel;import com.sun.media.jsdt.*;import java.awt.*;import java.applet.Applet;import javax.media.bean.playerbean.*;import javax.media.*;import java.util.Vector;import javax.media.protocol.DataSource;import javax.media.format.*;import javax.media.Time;import javax.media.MediaLocator;import javax.media.protocol.*;import java.io.IOException;import java.awt.Dimension;import com.sun.media.ui.*;import javax.media.bean.playerbean.*;class ChatConsumer implements ChannelConsumer, ChatDebugFlags { protected Buffer audioBuffer=new Buffer(); AudioFormat audioFormat; audioPanel myUser = null; public ChatConsumer(String name,audioPanel _chatUser) {// System.out.println("\u00B4\u00B4\u00BD¨\u00D2\u00BB\u00B8\u00F6\u00CF\u00FB·\u00D1\u00D5\u00DF"); this.myUser = _chatUser; //audioFormat = new AudioFormat(AudioFormat.LINEAR, 8000.0, 8,1,Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8,Format.NOT_SPECIFIED,Format.byteArray); audioFormat= new AudioFormat(AudioFormat.LINEAR,44100,16,1,AudioFormat.BIG_ENDIAN,AudioFormat.SIGNED); if (ChatConsumer_Debug) { System.err.println("ChatConsumer: constructor."); } } public synchronized void dataReceived(Data data) { myUser.processData(data); } public void setAudioBuffer(Buffer buffer){ audioBuffer=buffer; } } //\u00C4\u00DA\u00B2\u00BF\u00C0à LiveStream\u00B6\u00C1\u00C8\u00A1\u00CA\u00FD\u00BE\u00DD /* 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 AudioFormat audioFormat; protected boolean started; protected Thread thread; protected float frameRate = 20f; protected BufferTransferHandler transferHandler; protected Control [] controls = new Control[0];// protected Buffer audioBuffer=new Buffer(); protected boolean videoData = false; public LiveStream() { audioFormat = new AudioFormat(AudioFormat.LINEAR, 44100.0, 16, 2, Format.NOT_SPECIFIED, AudioFormat.UNSIGNED, 8, Format.NOT_SPECIFIED, Format.byteArray); maxDataLength = 1000;// Thread = new Thread(this); // new Thread(this).start(); } public ContentDescriptor getContentDescriptor() { return cd; } public long getContentLength() { return LENGTH_UNKNOWN; } public boolean endOfStream() { return false; } int seqNo = 0; double freq = 2.0; public void setAudioData(Buffer buffer){ audioBuffer=buffer; } public Format getFormat() { return audioFormat; } public void read(Buffer buffer) { System.out.println("the important method " + bufdata.size()); if(bufdata.size()>1){ synchronized (this) { try{ System.out.println("\u00B6\u00C1\u00CA\u00FD\u00BE\u00DDread()");// Object outdata = buffer.getData();// if (outdata == null || !(outdata.getClass() == Format.byteArray) ||// ((byte[])outdata).length < maxDataLength) {// outdata = new byte[maxDataLength];// buffer.setData(outdata);// }//// buffer.setFormat( audioFormat );// buffer.setTimeStamp( 1000000000 / 8 );// for (int i = 0; i < 1000; i++) {// ((byte[])outdata)[i] = (byte) (Math.sin(i / freq) * 32);// freq = (freq + 0.01);// if (freq > 10.0)// freq = 2.0;// }//// buffer.setSequenceNumber( seqNo );// buffer.setLength(maxDataLength);// buffer.setFlags(0);// buffer.setHeader( null );//// seqNo++; buffer.setData((byte[])(bufdata.firstElement())); bufdata.removeElementAt(0); System.out.println("bufdata\u00B5\u00C4\u00B4ó\u00D0\u00A1"+bufdata.size());// System.out.println("\u00BD\u00D3\u00CA\u00DC\u00B5\u00BD\u00B5\u00C4\u00CA\u00FD\u00BE\u00DD\u00C1÷\u00A3\u00BA");// System.out.println(bbyte);// if(bufdata.isEmpty()==false){// buffer.setData(bufdata.elementAt(0));// System.out.println("\u00BD\u00D3\u00CA\u00DC\u00B5\u00BD\u00B5\u00C4\u00CA\u00FD\u00BE\u00DD\u00C1÷\u00A3\u00BA"+(byte[])(bufdata.elementAt(0)));// bufdata.removeElementAt(0);// buffer.setFormat(audioFormat); buffer.setFormat((AudioFormat)bufFormat.elementAt(0)); System.out.println("wangsong\u00BD\u00D3\u00CA\u00DC\u00B5\u00BD\u00B5\u00C4\u00CA\u00FD\u00BE\u00DD\u00B8\u00F1\u00CA\u00BD:"); System.out.println((AudioFormat)bufFormat.elementAt(0)); System.out.println(audioFormat); bufFormat.removeElementAt(0); buffer.setSequenceNumber(((Long)(bufSeqnum.elementAt(0))).longValue()); bufSeqnum.removeElementAt(0);//// System.out.println(datavector.elementAt(2)); buffer.setLength(((Integer)(bufLength.elementAt(0))).intValue()); bufLength.removeElementAt(0);// buffer.setLength(1300); // buffer.setTimeStamp(((Long)(bufTimestamp.elementAt(0))).longValue());//// buffer.setTimeStamp(((Long)(bufTimestamp.elementAt(0))).longValue()); bufTimestamp.removeElementAt(0); buffer.setHeader(bufHeader.elementAt(0)); bufHeader.removeElementAt(0);//// System.out.println(datavector.elementAt(6)); buffer.setFlags(((Integer)(bufFlags.elementAt(0))).intValue()); bufFlags.removeElementAt(0);// buffer=(Buffer)bufdata.firstElement();//// bufdata.removeElementAt(0);// System.out.println("have buffer data");// buffer.setHeader(null);// buffer.setSequenceNumber(seqnum++);// seqnum++;// } System.out.println("bufdata\u00C0\u00EF\u00C3\u00E6\u00B5\u00C4\u00D4\u00AA\u00CB\u00D8\u00CA\u00FD\u00BE\u00DD\u00B8\u00F6\u00CA\u00FD-1\u00A3\u00BA"+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("\u00BD\u00F8\u00C8\u00EB\u00C5\u00D0\u00B6\u00CF\u00D3\u00EF\u00BE\u00E4"); thread = new Thread(this); thread.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( 50 ); } 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 + -