• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get wav file reference from resource map  RSS feed

 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a resource map within a Single Frame Application view file, and I can set text and icons using the resource map without problem, eg:

In the resource file:



And then in the code:



My problem is that I want to get a wav file reference to pass into an AudioSystem object. I can test audio stuff as follows:



But I have tried several different ways without success to get a File reference to create the File object for getAudioInputStream.

Could anyone help please?

Thanks.

Mark.
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a better way (for my purposes) of using a wav file:



And then to use it:



But I still can't get my own wav file from a resource as explained in my earlier post.

Could anyone help?

Mark.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that:

new File(System.getenv("windir") + "/" + "media/Windows Ding.wav")

is effectively failing?
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh God no!

This works fine, but it is just a temporary workaround.

I have a resource map in a Swing Application Framework that works perfectly with text and icons.

For example in the resource file I have:



Then in the code I have:



But I want to use the resource map to get a reference to my wav file (eg "myError.wav" ) to pass into AudioSystem.getAudioInputStream().

The problem is I don't know how to get a file reference from the resource map, I had a few attempts but just can't get to it.

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'm not sure if you can pull File references directly from a ResourceMap, have you tried the intermediate step of:

File errorSoundFile = new File(myResourceMap.getString("myError.wav”));
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep I tried, it would be nice but it returns wtih FileNotFound
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense though because you'll effectively be saying:

File errorSoundFile = new File("/com/my/example/gui/resources/Error.wav");

Now depending on where you're starting from it's probably not going to be the correct path to the file. So you need to have a path that is correct from where you are making the call and/or have a defined prefix/context root to start from

e.g. File errorSoundFile = new File(CONTEXT_ROOT + myResourceMap.getString("myError.wav”));

Hope that made sense!
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the feedback so far.

Yes, the idea does make sense but my understanding is that the resourceMap already provides the context, that's how it can get the icon files.

Maybe I can't see the wood for the trees, I am brain dead trying to figure this one out, I just can't make any progress

Any other ideas?

Thanks.

Mark.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The subtle difference here is that you'd be bringing back a string from the ResourceMap (no context, it's not actually a lookup resource, think of it purely as a property in a property file) and using that string to try and create a new File, which has no knowledge of the context that ResourceMap does.

If a myResourceMap.getFile() was provided then you'd be actually using the ResourceMap and its inherent context to get the file, but I'm guessing the API doesn't provide that.

Hmm, actually I've just realised this is all Swing stuff right? Let me send you to that forum so the relevant experts can cast an eye on it (my Open Source project developers would laugh if they saw me trying to give Swing advice ;p)
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks for your help so far Martijn.

Let's hope the Swing experts can help, it's still giving me a BIG headache

Mark.
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand the problem correctly, your WAVE file is a resource, possibly located inside your JAR file.

If so, use getResourceAsStream to retrieve an InputStream to it, and write it to a temporary file. File has some methods for creating unique temporary files. If you also call deleteOnExit() on that temporary file you will leave little to no "garbage".
 
Ilya Leontyev
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you need to create your own Wav ResourceConverter?
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this link will be usefull to answer your question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!