• Post Reply Bookmark Topic Watch Topic
  • New Topic

Music file input streaming in Java  RSS feed

 
Sam Thompson
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:

What I am trying to do is write a program that will play a sound clip (as of right now it's in WMV format) in my Java program. However, though, for some reason, it can't seem to find it and won't play the desired WMV file. Can you figure out what I am doing wrong? My code is below...



Where should I put the WMV file so it can find the file? Other than that it should work perfectly. It keeps sending it to the catch statement and that's it. Where is it looking for the WMV file exactly? Where should I put the file so it CAN find it?

Also, would this also work if I wanted to play MP3s? Or would I need a different set of code? What would that be?

Thanks again for your time and consideration everyone.

S.T.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for your actual problem, my guess is that you're making an assumption about what the JVM considers to be the current directory, and that assumption is wrong. File system relative paths are tricky in Java. You're better off using an absolute path or one of the getResource() or getResourceAsStream() methods to find it relative to a classpath root.
 
Sam Thompson
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I do this exactly? How do I tell the computer where the file is- or where do I put it?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Thompson wrote:How would I do this exactly? How do I tell the computer where the file is-


It depends on what you know, what you can assume, what you want to be configurable, etc.

The simplest thing to code is to put it in a known location and provide the full path to that location when you access that file. That's not particularly flexible, and won't be well received if you distribute your software to others and tell them they have to put a file in a specific absolute path.

The next simplest thing to code is probably to use System.getProperty and specify the full path with a -D option at startup time.

There are many other possibilities, and it wouldn't make sense for me to go into all of them here.

or where do I put it?


That's entirely up to you. You just have to know how to find it. In some contexts, some locations make more sense than others, but in this case, there's no one right answer.


 
Sam Thompson
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do I provide the pathname of the wmv file? The line containing the filename itself (the very first line in the TRY block) didn't work when I put in the entire pathname. Would you put this in the getProperty() method?

I also remember you mentioning about the methods getResource() and getResourceAsStream(). How would you use these exactly? Would you put the pathname in them as parameters?

I apologize for all the questions. I am still learning this part of Java.

Thanks for your help,

S.T.
 
Paul Clapham
Sheriff
Posts: 22521
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Thompson wrote:The line containing the filename itself (the very first line in the TRY block) didn't work when I put in the entire pathname.


Didn't work? That isn't much information for us to go on, is it? Please read TellTheDetails and then post some more information.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Thompson wrote:Where do I provide the pathname of the wmv file?


I don't understand the question. If you're hardcoding it like you are the relative name now, you can just hardcode the full path instead in the same place. If you're using a system property, you can call getProperty() at the point where you're currently hardcoding the name.

I forgot to mention another, possibly simpler approach. Make the full path a command line arg, after the class name, and use the args[] parameter in main().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!