/[classpath]/classpath/java/applet/Applet.java
ViewVC logotype

Diff of /classpath/java/applet/Applet.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9.2.4 by gnu_andrew, Tue Aug 2 20:12:14 2005 UTC revision 1.9.2.5 by gnu_andrew, Sun Nov 27 21:00:36 2005 UTC
# Line 54  import javax.accessibility.AccessibleCon Line 54  import javax.accessibility.AccessibleCon
54  import javax.accessibility.AccessibleRole;  import javax.accessibility.AccessibleRole;
55  import javax.accessibility.AccessibleState;  import javax.accessibility.AccessibleState;
56  import javax.accessibility.AccessibleStateSet;  import javax.accessibility.AccessibleStateSet;
57    import javax.sound.sampled.AudioSystem;
58    import javax.sound.sampled.Clip;
59    import javax.sound.sampled.LineUnavailableException;
60    import javax.sound.sampled.UnsupportedAudioFileException;
61    
62  /**  /**
63   * This is the base applet class.  An applet is a Java program that   * This is the base applet class.  An applet is a Java program that
# Line 257  public class Applet extends Panel Line 261  public class Applet extends Panel
261     * Returns an audio clip from the specified URL. This clip is not tied to     * Returns an audio clip from the specified URL. This clip is not tied to
262     * any particular applet.     * any particular applet.
263     *     *
    * XXX Classpath does not yet implement this.  
    *  
264     * @param url the URL of the audio clip     * @param url the URL of the audio clip
265     * @return the retrieved audio clip     * @return the retrieved audio clip
266     * @throws NullPointerException if url is null     * @throws NullPointerException if url is null
# Line 267  public class Applet extends Panel Line 269  public class Applet extends Panel
269     */     */
270    public static final AudioClip newAudioClip(URL url)    public static final AudioClip newAudioClip(URL url)
271    {    {
272      // This requires an implementation of AudioClip in gnu.java.applet.      return new URLAudioClip(url);
     throw new Error("Not implemented");  
273    }    }
274    
275    /**    /**
# Line 521  public class Applet extends Panel Line 522  public class Applet extends Panel
522        return s;        return s;
523      }      }
524    } // class AccessibleApplet    } // class AccessibleApplet
525    
526      private static class URLAudioClip implements AudioClip
527      {
528        // The URL we will try to play.
529        // This is null if we have already tried to create an
530        // audio input stream from this URL.
531        private URL url;
532    
533        // The real audio clip.  This is null before the URL is read,
534        // and might be null afterward if we were unable to read the URL
535        // for some reason.
536        private Clip clip;
537        
538        public URLAudioClip(URL url)
539        {
540          this.url = url;
541        }
542    
543        private synchronized Clip getClip()
544        {
545          if (url == null)
546            return clip;
547          try
548            {
549              clip = AudioSystem.getClip();
550              clip.open(AudioSystem.getAudioInputStream(url));
551            }
552          catch (LineUnavailableException _)
553            {
554              // Ignore.
555            }
556          catch (IOException _)
557            {
558              // Ignore.
559            }
560          catch (UnsupportedAudioFileException _)
561            {
562              // Ignore.
563            }
564          url = null;
565          return clip;
566        }
567    
568        public void loop()
569        {
570          Clip myclip = getClip();
571          if (myclip != null)
572            myclip.loop(Clip.LOOP_CONTINUOUSLY);
573        }
574    
575        public void play()
576        {
577          Clip myclip = getClip();
578          if (myclip != null)
579            myclip.start();
580        }
581    
582        public void stop()
583        {
584          Clip myclip = getClip();
585          if (myclip != null)
586            {
587              myclip.stop();
588              myclip.setFramePosition(0);
589            }
590        }
591      }
592  } // class Applet  } // class Applet

Legend:
Removed from v.1.9.2.4  
changed lines
  Added in v.1.9.2.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26