This site requires JavaScript, please enable it in your browser!
Greenfoot back
Busch2207
Busch2207 wrote ...

2012/2/28

getting the length of a sound

Busch2207 Busch2207

2012/2/28

#
Hi everyone! I've got two questions about sounds: Is there a possibility to get the total length of a sound file? And: Can you start playing a sound from a given time position (e.g. from the middle)?
mjrb4 mjrb4

2012/2/28

#
This isn't possible using GreenfootSound - the easiest thing to do would be to work around the problems (hard coding the length of your sound if you need to know it for instance.) It may be possible if you want to use an external library such as JLayer directly.. but that wouldn't be the simplest solution under the sun!
Duta Duta

2012/2/28

#
Click me ^Found the above solution when I was making a music player in BlueJ
Busch2207 Busch2207

2012/2/28

#
Thank you for your comment, Duta. That is, what I was searching for! :D
Duta Duta

2012/2/29

#
I should probably mention this: When I was making my music player, when I would try loading an mp3 file I'd get an javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file exception. After making and running the following test class:
import javax.sound.sampled.*;
public class Test
{
    public static void main(String[] args)
    {
        AudioFileFormat.Type[] t = AudioSystem.getAudioFileTypes();
        for(int i = 0; i < t.length; i++)
        {
            System.out.println("" + t[i]);
        }
    }
}
I found that the only naturally supported file types are .wav, .au, and .aiff - to get support for mp3 files you have to do some searching about - I started looking around and then lost interest in the program (which I'll start up again soon - currently I've got basic functionality, but no more (time slider, open file dialogue, play/pause buttons and stop button) but I never got round to adding in playlists etcera. If you find something, please post it to save me some time searching around. Thanks
Busch2207 Busch2207

2012/2/29

#
Yes, of course I will do that. But at the moment I'm working on a loading screen for my new game.
You need to login to post a reply.