edit: I see a lot of other threads on Daniweb on this. But after 2+ hours of reading about Sound in Java, I'm even more frustrated, so I have some questions.

1. Is the Java Sound API sufficient for the following operations: Playing mp3 audio files, pausing, and fast forward/rewinding to various points in the song? I've been looking at JMF but it is frustrating me and I don't need any of the capabilities except what I just mentioned. JMF seems to have massive capabilities which I am sick of wading through, but I will if it is absolutely necessary.
2. This question assumes the Java sound API is good to use for my purposes: The Java Sound API says that a Clip allows you to "play sound from an arbitrary position in the clip". This would be helpful to implement fast forward and rewind, I would think. But it also says that a Clip is preloaded. . will a 4-8 minute song fit into memory ok, or should I use a SourceDataLine instead?
3. Does anyone have any other tips or resources?

Recommended Answers

All 16 Replies

wait: I just remembered, I think the reason I was looking into JMF to begin with is because the other java sound api doesn't support mp3 format by default. I'm going to sleep. Too frustrated.

I read your post twice - I am not sure what I am going to write here is useful. I know the fact the jmf mp3 plugin is only supported by MX operating system.

Sorry adatapost, but I have the jmf mp3 plugin installed and working on my Windows system.
http://java.sun.com/javase/technologies/desktop/media/jmf/mp3/download.html
Jmf should be capable of doing all the stuff specified in the OP's first post, but I have found it to be erratic and unreliable. I have had really good solid results from Quicktime using the QTJava SDK from Apple under Windows.

Ok, I will look into that then. I saw that mentioned as well at some point when I was wading through the countless Java Sound examples from 1998-2003, looking for something up to date. Lol.

This is incredibly frustrating. The installation instructions for QT for Java say to download the normal QT program, then in custom install, specify that you want QT for java. But there is no custom install... it just installs itself on my computer.

public class SampleAudio{
	public static void main(String[] args){
	try
	{
	File f = new File("pathname.mp3");
	Player m_Player = Manager.createPlayer(f.toURI().toURL());
	m_Player.start();
	}
	catch (Exception e)
	{
		
	}
	}
}

The above code is JMF and actually works for playing an mp3. However, the quality is pretty bad, and it seems to occasionally mess up (either wrong rate or something like that).

Also, as far as the QT for Java download thing being crappy, yes, the directions I found on apple's site were definitely incorrect. But I just went into my build path under my project in eclipse, clicked configure, add external jars, and went under program files, quicktime, and found QT Java (its a zip file) under one of the folders there. Then I added that, so hopefully it will actually work.

commented: I have nothing to add to this topic, never having worked with sound, but I figured I'd +rep to cheer you up! :) +17

The above code is JMF and actually works for playing an mp3. However, the quality is pretty bad, and it seems to occasionally mess up (either wrong rate or something like that).
.

That's what I found.
If the QT SDK samples don't give you enough, I can let you have a small sample class for simply playing an mp3 and doing a callback when it's finished - never intended for use outside its original context, but may be helpful.

Thanks for the offer. . I'll let you know if I need that. What do you mean by doing a callback btw?

What do you mean by doing a callback btw?

You start a file playing in a separate thread, but you probably want to know when it's finished. QT gives you a callback when its finished, but the syntax and the way you set that up are un-intuitive (to say the least).

Hello everyone,
I am doing a project in which one requirement is to play a sequence of audio files..can someone help me with this please...i am really running out of time i just have 1 month to finish my project...

why don't you look at my post on the previous page that shows how to do this. All you need to do besides using that code is to install the JMF stuff which you can do by following directions on google.

Hey thanks for the code bro. Thats working well for playing an audio file. As per my requirement i need to play the sequence of audio files in a particular folder in d order which the user wish to play. Can you please suggest me how to do this please....

Hello bro i didnt understand...i dnt think that is related to my requiremet....i need to play multiple audip files in a particular folder....and after playing each file there will be a question and once the subject answers the question and click next button the next file should start playing...please help me..

You can use the File class: construct a File object, specifying the directory (folder that contains your audio files), then use the File object to get a list of the audio files. Then use the code snippet that I posted on the other page to loop through each file in that directory, and play each. Your question would be the first thing in the loop, and once that question was answered the file would be played, then that process would repeat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.