Hey guys!!
i tried to implement some Background music but its not working and i dont know why =(
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());
u.addBranchGraph(addObjects());
Light(u);
// Add Method for background sound
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();
}
}
And this is the 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)
Can anyone help me out?? Did i forget to add something ??
best wishes
david