Hey guys !!!
edit: Oh i noticed i posted it twice. unfortunately i cant delete it :-/
I want to implement background music in java 3d !!! but for some reason it doesnt work and I dont know why =(
i hope someone can help me out =( maybe i just forgot to add something ? :-/
this is my code
public class World implements KeyListener {
JFrame frame = new JFrame();
TransparencyAttributes objTransp;
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
SimpleUniverse u = new SimpleUniverse(c);
Scene s = null;
TransformGroup ViewTG = u.getViewingPlatform().getViewPlatformTransform();
Transform3D ViewT3D = new Transform3D();
}
public World(){
TransparencyAttributes objTransp = new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f);
objTransp.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
objTransp.setTransparencyMode(TransparencyAttributes.BLENDED);
frame.add("Center",c);
frame.addKeyListener(this);
frame.setFocusable(true);
OrbitBehavior ob = new OrbitBehavior(c);
u.addBranchGraph(createSceneGraph());
//Add Method for BackgroundSound
u.addBranchGraph(createBackgroundSound());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1600, 850);
frame.setVisible(true);
ob.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE));
u.getViewingPlatform().setViewPlatformBehavior(ob);
}
public BranchGroup createSceneGraph(){
return RootBg;
}
private BranchGroup createBackgroundSound()
{
BranchGroup objGroup = new BranchGroup();
AudioDevice audioDev = u.getViewer().createAudioDevice();
if (!audioDev.initialize())
{
System.out.println("Failed to init audio device, exiting!");
System.exit(1);
}
MediaContainer rain = new MediaContainer("pte.wav");
rain.setCacheEnable(true);
BackgroundSound bgs = new BackgroundSound(rain, 1.0f);
bgs.setLoop(-1);
bgs.setEnable(true);
objGroup.addChild(bgs);
return objGroup;
}
public static void main(String[] args) {
World w = new World();
}
}
ERROR
java.lang.UnsupportedOperationException: No AudioDevice specified
at com.sun.j3d.utils.universe.Viewer.createAudioDevice(Viewer.java:986)
at World.createBackgroundSound(World.java:198)
at World.<init>(World.java:111)
at World.main(World.java:1124)
Java 3D: audio is disabled
Exception in thread "main" java.lang.NullPointerException
at World.createBackgroundSound(World.java:199)
at World.<init>(World.java:111)
at World.main(World.java:1124)
it would be so nice if someone would help me :persecutioncomplex:
best wishes
david