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

📄 statehelper.java

📁 一些基本的代码,还有一些事例.值得一看
💻 JAVA
字号:
package jsounddemo2;import javax.media.ControllerListener;import javax.media.ControllerEvent;import javax.media.*;import javax.media.control.*;import javax.media.datasink.*;import javax.media.format.*;import javax.media.protocol.*;public class StateHelper implements ControllerListener {  Player player = null;  boolean configured = false;  boolean realized = false;  boolean prefetched = false;  boolean failed = false;  boolean closed = false;  public StateHelper(Player player) {    this.player=player;    this.player.addControllerListener(this);  }  public boolean configure(int timeOutMillis){    long startTime = System.currentTimeMillis();    synchronized(this){      if (player instanceof Processor){        ((Processor)player).configure();      }else{        return false;      }      while (!configured && !failed){        try{          wait(timeOutMillis);        }catch(InterruptedException err){        }        if (System.currentTimeMillis()-startTime>timeOutMillis)          break;      }    }    return this.configured;  }  public boolean realize(int timeOutMillis){    long startTime = System.currentTimeMillis();    synchronized(this){      player.realize();      while(!realized && !failed){        try{          wait(timeOutMillis);        }catch(InterruptedException err){        }        if (System.currentTimeMillis()-startTime>timeOutMillis)          break;      }    }    return this.realized;  }  public boolean prefetch(int timeOutMillis){    long startTime = System.currentTimeMillis();    synchronized(this){      player.prefetch();      while( !prefetched && !failed){        try{          wait(timeOutMillis);        }catch(InterruptedException err){        }        if (System.currentTimeMillis()-startTime>timeOutMillis)          break;      }    }    return this.prefetched;  }  public void close(){    synchronized(this){      player.close();      while (!closed){        try{          wait(200);        }catch(InterruptedException err){        }      }    }    player.removeControllerListener(this);  }  public void controllerUpdate(ControllerEvent parm1) {    /**@todo Implement this javax.media.ControllerListener method*/    //throw new java.lang.UnsupportedOperationException("Method controllerUpdate() not yet implemented.");    if (parm1 instanceof RealizeCompleteEvent)      this.realized = true;    else      if (parm1 instanceof ConfigureCompleteEvent)        this.configured = true;      else        if (parm1 instanceof PrefetchCompleteEvent)          this.prefetched = true;        else          if (parm1 instanceof ControllerErrorEvent)            this.failed = true;          else            if (parm1 instanceof ControllerClosedEvent)              this.closed = true;            else              return;    notifyAll();  }}

⌨️ 快捷键说明

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