Issues regarding playing audio files in a JME midlet.

Posted by Northernen on Stack Overflow See other posts from Stack Overflow or by Northernen
Published on 2010-06-07T04:57:05Z Indexed on 2010/06/07 5:02 UTC
Read the original article Hit count: 218

Filed under:
|
|

I am making a midlet which is to be used to play out local audio files. It is obviously not working. I am getting a null reference on the "is" variable, in the code snippet shown below.

1. try{
2. System.out.println("path: " + this.getClass());
3. InputStream is = this.getClass().getResourceAsStream("res/01Track.wav");
4. p1=Manager.createPlayer(is, "audio");
5. p1.realize();            
6. p1.prefetch();
7. p1.start();
8. }
9. catch(Exception e){
10. System.out.println(e.getMessage());
11. }

I assume there is something wrong with the "this.getClass().getResourceAsStream("res/01Track.wav")" bit, but I can not for the life of me figure out why, and I have tried referring to the file in 20 different ways.

If I printline "this.getClass()" it gives me "path: class Mp3spiller". The absolute path to "01Track.wav" is "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller\res\01Track.wav". Am I completely wrong in thinking that I should refer relatively to "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller"?

If anyone could point out what I am doing wrong, I would be grateful. I have basically stolen the code from a tutorial I found online, so I would have thought it would be working.

© Stack Overflow or respective owner

Related posts about audio

Related posts about java-me