harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r607111 - in /harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer: ViewerAppletContext.java ViewerAudioClip.java
Date Thu, 27 Dec 2007 19:31:45 GMT
Author: apetrenko
Date: Thu Dec 27 11:31:45 2007
New Revision: 607111

URL: http://svn.apache.org/viewvc?rev=607111&view=rev
Log:
Applet context now loads images and sound clips.
Initial version of applet audio clip to play midi sound.

Added:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
  (with props)
Modified:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java?rev=607111&r1=607110&r2=607111&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
Thu Dec 27 11:31:45 2007
@@ -21,6 +21,7 @@
 import java.applet.AppletContext;
 import java.applet.AudioClip;
 import java.awt.Image;
+import java.awt.Toolkit;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -28,6 +29,8 @@
 import java.util.Iterator;
 
 class ViewerAppletContext implements AppletContext {
+	public ViewerAppletContext() {
+	}
 
 	public Applet getApplet(String name) {
 		// TODO Auto-generated method stub
@@ -40,13 +43,11 @@
 	}
 
 	public AudioClip getAudioClip(URL url) {
-		// TODO Auto-generated method stub
-		return null;
+		return new ViewerAudioClip(url);
 	}
 
 	public Image getImage(URL url) {
-		// TODO Auto-generated method stub
-		return null;
+		return Toolkit.getDefaultToolkit().createImage(url);
 	}
 
 	public InputStream getStream(String key) {

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java?rev=607111&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
Thu Dec 27 11:31:45 2007
@@ -0,0 +1,63 @@
+package org.apache.harmony.tools.appletviewer;
+
+import java.applet.AudioClip;
+import java.net.URL;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+import javax.sound.midi.Transmitter;
+
+class ViewerAudioClip implements AudioClip {
+	//private Clip clip;
+	private Sequencer sequencer;
+	
+	public ViewerAudioClip(URL url) {
+		try {
+			sequencer = MidiSystem.getSequencer();
+			sequencer.open();
+			
+			Sequence sequence = MidiSystem.getSequence(url);
+			sequencer.setSequence(sequence);
+			
+			if (!(sequencer instanceof Synthesizer)) {
+				Synthesizer synthesizer = MidiSystem.getSynthesizer();
+				synthesizer.open();
+				Receiver receiver = synthesizer.getReceiver();
+				Transmitter transmitter = sequencer.getTransmitter();
+				transmitter.setReceiver(receiver);
+			}
+		} catch (Exception e) {
+			sequencer = null;
+		}
+//		try {
+//			this.clip = AudioSystem.getClip();
+//			clip.open(AudioSystem.getAudioInputStream(url));
+//		} catch (Exception e) {
+//			this.clip = null;
+//		}		
+	}
+
+	public void loop() {
+		if (sequencer != null)
+			sequencer.start();
+//		if (clip != null) 
+//			clip.loop(Clip.LOOP_CONTINUOUSLY);
+	}
+
+	public void play() {
+		if (sequencer != null)
+			sequencer.start();
+//		if (clip != null) 
+//			clip.start();		
+	}
+
+	public void stop() {
+		if (sequencer != null)
+			sequencer.stop();
+//		if (clip != null) 
+//			clip.stop();
+	}
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message