• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get wav file reference from resource map

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep I tried, it would be nice but it returns wtih FileNotFound
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22787
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be you need to create your own Wav ResourceConverter?
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope this link will be usefull to answer your question.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic