Пример #1
0
 private void closePlayer() {
   if (null != player) {
     try {
       player.stop();
     } catch (Exception e) {
     }
     try {
       player.close();
     } catch (Exception e) {
     }
     player = null;
   }
 }
Пример #2
0
 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
 // 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
  /* 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();
    }
  }