home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / Gamelication / com / next / gt / RCS / AudioManager.java,v < prev    next >
Text File  |  1998-04-20  |  2KB  |  115 lines

  1. head    1.2;
  2. access;
  3. symbols;
  4. locks
  5.     jgh8962:1.2; strict;
  6. comment    @# @;
  7.  
  8.  
  9. 1.2
  10. date    98.04.15.15.35.12;    author mds1274;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    98.04.14.00.56.35;    author jgh8962;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @*** empty log message ***
  27. @
  28. text
  29. @/**
  30.  * AudioManager.java
  31.  * @@author Jeremy Hutchins, idea from: Bhagvan Kommadi
  32.  */
  33.  
  34. package com.next.gt;
  35.  
  36. import sun.audio.*;
  37. import java.io.*;
  38.  
  39.  /**
  40.   * Plays a audio files (.au format)
  41.   */
  42.  
  43. public class AudioManager extends java.applet.Applet
  44.                              implements Runnable
  45. {
  46.     private Thread _kicker = null;
  47.     private int _naptime = 5;
  48.     private boolean _keepRunning = true;
  49.  
  50.    public void run()
  51.     {
  52.     while (_keepRunning)
  53.         {
  54.         try
  55.                  {
  56.                    _kicker.sleep(_naptime);
  57.                  }
  58.                 catch (InterruptedException e) {};
  59.     } 
  60.  
  61.    }
  62.  
  63.    public void start()
  64.    {
  65.     _kicker = new Thread(this);
  66.     _kicker.start();
  67.    }
  68.  
  69.    /**
  70.     * Open the audiostream and 
  71.     * play the audiofile by the AudioPlayer
  72.     */
  73.    public void play(String fileName)
  74.    {
  75.          AudioStream as;
  76.         try
  77.         {
  78.                 as = new AudioStream(new FileInputStream(fileName));
  79.                 AudioPlayer.player.start(as);
  80.  
  81.         }
  82.         catch (IOException e) {
  83.                 System.err.println("Can't open audio stream");
  84.         }
  85.    }
  86.  
  87.    /**
  88.     * resume playing the sound
  89.     */
  90.    public void resumeplay(String fileName)
  91.    {
  92.       AudioPlayer.player.resume();
  93.    }
  94.  
  95.    /**
  96.     * suspend the player
  97.     */
  98.  
  99.    public void stopplay( )
  100.    {
  101.        AudioPlayer.player.suspend();
  102.    }
  103.  
  104. }
  105. @
  106.  
  107.  
  108. 1.1
  109. log
  110. @Initial revision
  111. @
  112. text
  113. @d5 3
  114. @
  115.