示例#1
0
文件: Notify.java 项目: fin-nick/fj
 private void closePlayer() {
   if (null != player) {
     try {
       player.stop();
     } catch (Exception e) {
     }
     try {
       player.close();
     } catch (Exception e) {
     }
     player = null;
   }
 }
示例#2
0
文件: Notify.java 项目: fin-nick/fj
 private boolean play(String file, int volume) {
   createPlayer(file);
   if (null == file) {
     return false;
   }
   try {
     player.realize();
     setVolume(volume);
     player.prefetch();
     player.start();
   } catch (Exception e) {
     closePlayer();
     return false;
   }
   return true;
 }
示例#3
0
文件: Notify.java 项目: fin-nick/fj
 // sets volume for player
 private void setVolume(int value) {
   try {
     VolumeControl c = (VolumeControl) player.getControl("VolumeControl");
     if ((null != c) && (0 < value)) {
       c.setLevel(value);
     }
   } catch (Exception e) {
   }
 }
示例#4
0
文件: Notify.java 项目: fin-nick/fj
  /* Creates player for file 'source' */
  private void createPlayer(String source) {
    closePlayer();
    try {
      /* What is file extention? */
      String ext = "wav";
      int point = source.lastIndexOf('.');
      if (-1 != point) {
        ext = source.substring(point + 1).toLowerCase();
      }

      InputStream is = getClass().getResourceAsStream(source);
      if (null != is) {
        player = Manager.createPlayer(is, getMimeType(ext));
        player.addPlayerListener(this);
      }
    } catch (Exception e) {
      closePlayer();
    }
  }