Couldn't find a section for this to go in, so I chose this one. I play sounds using the following code:
To stop the sound (where AS is the object from above), I do...
This works, but after pressing stop, the sound continues for about another second, before it comes to an end. The point is, I want to trigger another sound after closing this one, and at the moment, when I stop first sound it continues slightly, but the second sound starts as soon as I press the stop button to close first, so there is a small overlap in the sounds.
I'm not totally sure why this happens, I think it reads in so many bytes at a time, then plays them.
Is there anyway to stop this? I considered using a SwingTimer, put onto 1 second, so the second sound, waits a second, giving no overlap. But I don't really like this, I would rather stop first sound dead if possible.
You could (perhaps even should*) switch to the Java Media Framework. This includes a class called Player which can also play media files - not only sounds but some movies as well. To these players you can attach ControllerListeners - with these you can find exactly find out when a piece of music ends. Using this I even wrote a multi-player, a class that can play multiple sounds one after another. You create players using the Manager class.
The only real tricky part is that each piece of music has to be realized first, then prefetched, and only then it can be played.
* When I load the AudioPlayer class I get a warning it may be removed in the future. You shouldn't use classes from com.sun.*, sun.* and sunw.* packages because these are only there for internal use of the JRE. There is a reason these aren't documented. [ October 22, 2007: Message edited by: Rob Prime ]
How can I install this package? Also, I'm building an application that needs to be distributed to people by download, the JMF would cause a problem wouldn't it?
I basically just want to play wav files in an application, and I'd like to bundle everything into a JAR file, with a couple of external folders for images, do you think JMF could be a problem for other users, if they are not java knowledgable?
Distributing JMF with your Java software Sun Microsystems allows vendors to distribute JMF 2.1.1e with their Java software, as long as their software uses JMF 2.1.1e and provided they follow the terms of the JMF 2.1.1e Binary Code License agreement. This document uses the term "vendors" to refer to licensees, developers, and independent software vendors (ISVs) who license and distribute the JMF with their Java programs.
You should check out that Binary Code License agreement, but it may allow you to put the JMF classes inside your JAR file as well, or link to the JMF JARs from your JAR (using the Class-Path MANIFEST directive).
Joined: Apr 11, 2005
Thanks, is there any simple tutorial I can use to start. Would you recommendweb page
Any way, I installed JMF2.1.1e, then inside Eclipse, I went to the project on the filesystem, 'Configure Build Path'-> then added external jmf.jar thats inside the lib folder of JMF2.1.1e
Then I tried out a wav file, and it worked. I just tried an mp3 file, and that worked too, so far so good.
But thinking ahead, is it possible to include this jar file in the jar file for the project, so I can basically give the project to a user who has jdk1.4 or higher, and they can play sounds without having to configure anything?
Thanks very much [ October 22, 2007: Message edited by: colin shuker ]
Joined: Apr 11, 2005
OK, I exported the whole project including the jmf.jar to a jar on me desktop. The project.jar file worked fine, and the sound played. If I uninstall the JMF2.1.1e software, and retry the project.jar, it no longer works,
So for a different user on a pc, would they also be required to install JMF2.1.1e so that the project.jar file can then play the sound?
Thanks [ October 22, 2007: Message edited by: colin shuker ]
Well they could, but if the license allows it, you can unzip the jmf JAR file, then add its contents and the jmf.properties file to your own JAR file (the properties file goes in the root of the JAR).
It may be possible though that you need some of the other JMF JAR files too - include their contents as well.
Joined: Apr 11, 2005
currently what I do is, grab the jmf.jar file from the lib directory,
Within Eclipse, I add it (as a jar file) to the Build Path of project, along with... JRE System Library [j2sdk1.4.2_14].
When I jar the project and run it, the sounds play, but uninstalling JMF2.1.1e, and running the project, there is no sound.
I've taken a look at the lib directory of JMF2.1.1e, it contains the following jars: jmf.jar customizer.jar mediaplayer.jar multiplayer.jar sound.jar
As well as 3 other files... jmf.properties jmf.properties.orig soundbank.gm
I've tried adding all these jars to the Build Path ,and placing jmf.properties at the root of the project, but if I uninstall JMF2.1.1e, then program doesn't run at all, from eclipse IDE, or from jar file of project.
Perhaps only way is for user to install the JMF2.1.1e I'm not sure, doesn't seem to be much internet information available on this.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com