Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - megatlantis

Pages: [1]
1
Other Support / play mp3 song from online file
« on: October 07, 2012, 04:31:40 PM »
hello , i'm trying to play a mp3 file from a url but i go a nullpointerexception when i set the rawdatastream .
thanks for helping me  !
this code first try to play local file located in my .jar , and if no exist it will gonna try take one from my server .
here is my code :

Code: [Select]
       
 try{
                                InputStream audioSrc =getClass().getResourceAsStream("cimsound/"+soundname);
        AudioInputStream in;
        if(audioSrc==null){
                   URL url = new URL("http://xxx.xx/"+soundname);
                     in = AudioSystem.getAudioInputStream(url);
        }else{
        InputStream bufferedIn = new BufferedInputStream(audioSrc);
in = AudioSystem.getAudioInputStream(bufferedIn);
        }
            AudioInputStream din = null;
            AudioFormat baseFormat = in.getFormat();
            AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                    baseFormat.getSampleRate(),
                    16,
                    baseFormat.getChannels(),
                    baseFormat.getChannels() * 2,
                    baseFormat.getSampleRate(),
                    false);
            din = AudioSystem.getAudioInputStream(decodedFormat, in);
    ss.rawDataStream(decodedFormat, true, "test",0, 0, 0, 0, 0.0f); //nullpointer from here



                ss.setPitch("test", 1);
                ss.setVolume("test", 1);
                ss.play("test");
}catch (Exception e)
        {
            System.out.println(e);
        }

Pages: [1]