Try adding:
AudioDevice audioDev = simpleU.getViewer().createAudioDevice();
(Looks like you are using "u" instead of "simpleU" as your
SimpleUniverse variable.)
- John Wright
Starfire Research
sreelatha menon wrote:
>
> I'm trying to play a background sound file with a Canvas animating some
> graphics. It doesn't play the sound. Does anyone know what else I need to add
> to the following code? Any help will be appreciated.
>
> public void init()
> {
> GraphicsConfiguration config =
> SimpleUniverse.getPreferredConfiguration();
> MyCanvas3D c = new MyCanvas3D(config);
>
> setLayout(new BorderLayout());
> add("Center", c);
>
> BranchGroup scene = createSceneGraph();
> SimpleUniverse u = new SimpleUniverse(c);
>
> u.getViewingPlatform().setNominalViewingTransform();
> u.addBranchGraph(scene);
> }
>
> private BranchGroup createSceneGraph() {
>
> BranchGroup objRoot = new BranchGroup();
>
> TransformGroup objTrans = new TransformGroup();
> objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
> objRoot.addChild(objTrans);
>
> BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
> 100.0);
>
> try
> {
>
> MediaContainer sample = new MediaContainer(new
> URL("file:bgm.au"));
> sample.setCapability(MediaContainer.ALLOW_URL_WRITE);
> sample.setCapability(MediaContainer.ALLOW_URL_READ);
> sample.setCacheEnable(false);
> sound = new BackgroundSound(sample, 2.0F);
> sound.setLoop(1);
> sound.setContinuousEnable(true);
>
> sound.setReleaseEnable(true);
> sound.setCapability(PointSound.ALLOW_ENABLE_WRITE);
> sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE);
> sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE);
>
>sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE);
> sound.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE);
> sound.setCapability(PointSound.ALLOW_RELEASE_WRITE);
> sound.setCapability(PointSound.ALLOW_DURATION_READ);
> sound.setCapability(PointSound.ALLOW_IS_PLAYING_READ);
> sound.setCapability(PointSound.ALLOW_LOOP_WRITE);
> sound.setCapability(PointSound.ALLOW_IS_READY_READ);
>
> sound.setEnable(true);
>
> BoundingSphere soundBounds =
>new BoundingSphere(new
> Point3d(0.0,0.0,0.0), 500.0);
> sound.setSchedulingBounds(soundBounds);
> objTrans.addChild(sound);
>
> objRoot.compile();
>
> }
> catch (MalformedURLException ex)
> {
> System.out.println("MalformedURL");
> }
>
> return objRoot;
> }
>
> ____________________________________________________________________
> Get free email and a permanent address at http://www.netaddress.com/?N=1
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".