Hi, ich hab schon danach gegoogled und die Api gelesen, aber keine Beispiel gefunden, dass auf meinem Compúter funktioniert. Kann mir einer helfen, und mir ein Beispiel dazu geben, wie man den "Point Sound" verwendet, bitte?
PointSound s = new PointSound("Pfad zum Sound",x,y,z,);
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
public class Test_Class extends Applet {
private SimpleUniverse universe ;
private Canvas3D canvas;
private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 10.0), 1000.0);
public void setupView()
{
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
//hier!!!
objRoot.addChild(new Bush().Bush());
try {
objRoot.addChild(new PointSound(new MediaContainer(new URL("F:/Rayman/Sound.Library/Pirates.wav")),2,2,2, 2));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//hier!!!
Color3f lightColor = new Color3f(.6f,.6f,.6f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public void init() {
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
}
public void destroy() {universe.removeAllLocales();}
public static void main(String[] args) {new MainFrame(new Test_Class(), 256, 256);}
}
Exception in thread "Thread-3" javax.media.j3d.SoundException: MediaContainer: setURL - bad URL
at javax.media.j3d.MediaContainerRetained.setURLString(MediaContainerRetained.java:116)
at javax.media.j3d.MediaContainerRetained.setURLString(MediaContainerRetained.java:94)
at javax.media.j3d.MediaContainer.<init>(MediaContainer.java:95)
at Plant.Test_Class.createSceneGraph(Test_Class.java:34)
at Plant.Test_Class.init(Test_Class.java:48)
at com.sun.j3d.utils.applet.MainFrame.run(MainFrame.java:267)
at java.lang.Thread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Plant.Test_Class.destroy(Test_Class.java:59)
at com.sun.j3d.utils.applet.MainFrame$1.windowClosing(MainFrame.java:226)
at java.awt.Window.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Plant.Test_Class.destroy(Test_Class.java:59)
at com.sun.j3d.utils.applet.MainFrame$1.windowClosing(MainFrame.java:226)
at java.awt.Window.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Plant.Test_Class.destroy(Test_Class.java:59)
at com.sun.j3d.utils.applet.MainFrame$1.windowClosing(MainFrame.java:226)
at java.awt.Window.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
objRoot.addChild(new PointSound(new MediaContainer("F:/Rayman/Sound.Library/Pirates.wav"),2,2,2, 2));
Exception in thread "Thread-3" javax.media.j3d.SoundException: MediaContainer: setURL - bad URL
at javax.media.j3d.MediaContainerRetained.setURLString(MediaContainerRetained.java:116)
at javax.media.j3d.MediaContainerRetained.setURLString(MediaContainerRetained.java:94)
at javax.media.j3d.MediaContainer.<init>(MediaContainer.java:95)
at Plant.Test_Class.createSceneGraph(Test_Class.java:38)
at Plant.Test_Class.init(Test_Class.java:53)
at com.sun.j3d.utils.applet.MainFrame.run(MainFrame.java:267)
at java.lang.Thread.run(Unknown Source)
objRoot.addChild(new PointSound(new MediaContainer("file:F:/Rayman/Sound.Library/Pirates.wav"),2,2,2, 2));
objRoot.addChild(new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),20,0,0,0));
PointSound p = null;
try {
p = new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),50,0,0,0);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.setSchedulingBounds(bounds);
objRoot.addChild(p);
Soweit sind wir schonmal, und an MidNIgis, Frage, ja, man muss das "file:///" davor setzten.Java:PointSound p = null; try { p = new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),50,0,0,0); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setSchedulingBounds(bounds); objRoot.addChild(p);
Sonst klappt es nicht
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
public class Test_Class extends Applet {
private SimpleUniverse universe ;
private Canvas3D canvas;
private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0);
public void setupView()
{
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
//hier!!!
PointSound p = null;
try {
p = new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),50,0,0,0);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.setSchedulingBounds(bounds);
objRoot.addChild(p);
//hier!!!
Color3f lightColor = new Color3f(.6f,.6f,.6f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public void init() {
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
}
public void destroy() {universe.removeAllLocales();}
public static void main(String[] args) {new MainFrame(new Test_Class(), 256, 256);}
}
PointSound p = null;
try {
p = new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),50,0,0,0);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.setSchedulingBounds(bounds);
p.isPlaying();
PointSound p = null;
try {
p = new PointSound(new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/THEME.wav")),1,0,0,0);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
p.setSchedulingBounds(bounds);
p.setEnable(true);
objRoot.addChild(p);
import com.sun.j3d.audioengines.javasound.JavaSoundMixer;
// ...
// Dann beim Initialisieren:
PhysicalEnvironment environment = universe.getViewer().getPhysicalEnvironment();
AudioDevice device = new JavaSoundMixer(environment);
device.initialize();
environment.setAudioDevice(device);
das klappt bei mir setEnable true
nicht
über all bei all Exaples ist die Rede von JOAL
eine Frage. könnt ihrs starten nur mit dem Normalen Java3D Package?
Kennt er denn schon den Unterschied zwischen relativen Pfaden und absoluten?ich versteh eh nicht wieso da in seinen Codeschnipseln überall ABSOLUTE Pfade drinstehen? Statt dass er relative verwendet, die in sein Projekt zeigen ... das muss man doch später alles wieder umbauen und vor allem wiederfinden!
Gibt es schon ein Dictionary: Deutsch-DevX; DevX-Deutsch?
fast@ILLUVATOR
Der Satz macht leider keinen Sinn 0odann nante ich die init methode in eine public um
Bei mir funktionierts. Dann steht ja jetzt wohl Aussage gegen Aussageund änderte das ganze in extends JFrame
dann hatts aber immer noch nicht funktioniert.
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
public class Test_Class extends JFrame
{
private SimpleUniverse universe ;
private Canvas3D canvas;
private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0);
public void setupView()
{
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
//hier!!!
MediaContainer myWave = null;
try {
myWave = new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/Sounds/MainSound.wav"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Point2f[] myAtten = {
new Point2f( 100.0f, 1.0f ),
new Point2f( 350.0f, 0.5f ),
new Point2f( 600.0f, 0.0f )
};
PointSound mySound = new PointSound( );
mySound.setSoundData( myWave );
mySound.setEnable( true );
mySound.setInitialGain( 1.0f );
mySound.setLoop( -1 ); // Loop forever
mySound.setPosition( new Point3f( 0.0f, 1.0f, 0.0f ) );
mySound.setDistanceGain( myAtten );
BoundingSphere myBounds = new BoundingSphere(
new Point3d( ), 1000.0 );
mySound.setSchedulingBounds( myBounds );
objRoot.addChild(mySound);
//hier!!!
Color3f lightColor = new Color3f(.6f,.6f,.6f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public Test_Class()
{
setVisible(true);
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
}
public void destroy() {universe.removeAllLocales();}
public static void main(String[] args) {new Test_Class();}
}
Hier mein Code als JFrame:
...
objRoot.addChild(new Sphere(0.1f));
is absicht, aber kannst du was hören?![]()
ich hoffe doch sehr, du hast daran gedacht den PFad zur mUsik zu verändern oder?
Wenn nicht, nehm einen längeren Sound. den du auf deinem PC hast du starte ihn dann
und sag mir dann, kannst du was hören?
ja, also hörst du was?
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.j3d.audioengines.javasound.JavaSoundMixer;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
public class Test_Class extends JFrame
{
private SimpleUniverse universe ;
private Canvas3D canvas;
private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0);
public void setupView()
{
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
//hier!!!
objRoot.addChild(new Bush().Bush());
MediaContainer myWave = null;
try {
myWave = new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/Sounds/MainSound.wav"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Point2f[] myAtten = {
new Point2f( 100.0f, 1.0f ),
new Point2f( 350.0f, 0.5f ),
new Point2f( 600.0f, 0.0f )
};
PointSound mySound = new PointSound( );
mySound.setSoundData( myWave );
mySound.setEnable( true );
mySound.setInitialGain( 1.0f );
mySound.setLoop( -1 ); // Loop forever
mySound.setPosition( new Point3f( 0.0f, 1.0f, 0.0f ) );
mySound.setDistanceGain( myAtten );
BoundingSphere myBounds = new BoundingSphere(
new Point3d( ), 1000.0 );
mySound.setSchedulingBounds( myBounds );
objRoot.addChild(mySound);
//hier!!!
Color3f lightColor = new Color3f(.6f,.6f,.6f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public Test_Class()
{
setVisible(true);
PhysicalEnvironment environment = universe.getViewer().getPhysicalEnvironment();
AudioDevice device = new JavaSoundMixer(environment);
device.initialize();
environment.setAudioDevice(device);
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
}
public static void main(String[] args) {new Test_Class();}
}
Exception in thread "main" java.lang.NullPointerException
at Plant.Test_Class.<init>(Test_Class.java:81)
at Plant.Test_Class.main(Test_Class.java:98)
geht imer noch nicht+ Fehlermeldung
Java:import java.awt.BorderLayout; import java.awt.GraphicsConfiguration; import java.net.MalformedURLException; import java.net.URL; import com.sun.j3d.audioengines.javasound.JavaSoundMixer; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.swing.JFrame; import javax.vecmath.*; import com.sun.j3d.utils.behaviors.vp.*; public class Test_Class extends JFrame { private SimpleUniverse universe ; private Canvas3D canvas; private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0); public void setupView() { OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM); orbit.setSchedulingBounds(bounds); ViewingPlatform viewingPlatform = universe.getViewingPlatform(); viewingPlatform.setNominalViewingTransform(); viewingPlatform.setViewPlatformBehavior(orbit); } public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); //hier!!! objRoot.addChild(new Bush().Bush()); MediaContainer myWave = null; try { myWave = new MediaContainer(new URL("file:///F:/Rayman/Sound.Library/Sounds/MainSound.wav")); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Point2f[] myAtten = { new Point2f( 100.0f, 1.0f ), new Point2f( 350.0f, 0.5f ), new Point2f( 600.0f, 0.0f ) }; PointSound mySound = new PointSound( ); mySound.setSoundData( myWave ); mySound.setEnable( true ); mySound.setInitialGain( 1.0f ); mySound.setLoop( -1 ); // Loop forever mySound.setPosition( new Point3f( 0.0f, 1.0f, 0.0f ) ); mySound.setDistanceGain( myAtten ); BoundingSphere myBounds = new BoundingSphere( new Point3d( ), 1000.0 ); mySound.setSchedulingBounds( myBounds ); objRoot.addChild(mySound); //hier!!! Color3f lightColor = new Color3f(.6f,.6f,.6f); AmbientLight ambientLight= new AmbientLight(lightColor); ambientLight.setInfluencingBounds(bounds); objRoot.addChild(ambientLight); DirectionalLight directionalLight = new DirectionalLight(); directionalLight.setColor(lightColor); directionalLight.setInfluencingBounds(bounds); objRoot.addChild(directionalLight); return objRoot; } public Test_Class() { setVisible(true); PhysicalEnvironment environment = universe.getViewer().getPhysicalEnvironment(); AudioDevice device = new JavaSoundMixer(environment); device.initialize(); environment.setAudioDevice(device); BranchGroup scene = createSceneGraph(); setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas = new Canvas3D(config); add("Center", canvas); universe = new SimpleUniverse(canvas); setupView(); universe.addBranchGraph(scene); } public static void main(String[] args) {new Test_Class();} }
Code:Exception in thread "main" java.lang.NullPointerException at Plant.Test_Class.<init>(Test_Class.java:81) at Plant.Test_Class.main(Test_Class.java:98)
MidNIgi, bitte, wieso hör ich den Sound über all?