Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading an MP3 from a URL to a local file

 
Petereyup Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to copy an MP3 from my website to a local file - the following program SOMETIMES!!?? works, sometimes it get so far and then stops -it does not end just sticks at a random point,and i have to cancel the program ( I am using Netbeans), but it does work on the odd occasion?! my main aim to have this in a swing application using swingworker, and to update a status bar etc.....

Any help would be greatly appreciated!
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

That > 0 should be >= 0, > -1 or != -1. 0 itself is a perfectly valid return value that does not indicate the end of the stream. That's what -1 is for.
 
Petereyup Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried !=-1 and >=0, it still sometimes works and sometimes just get stuck within the loop, but no new println's are produced - it just hangs!

Thanks for the tip though!
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've modified the loop as I suggested, then I don't see anything wrong with your code. Perhaps there is a problem with the network, or with the server you're getting the MP3 file from. Can you download the file from a regular browser?
 
Petereyup Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if it was the network - sometimes when I watch a streamed video through BBC's Iplayer, it stops ,then starts again with the sound out of sink with the video, and internet radio sometimes just stops!! - I will try it on a friends network.

Thanks
 
Petereyup Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done some more research : downloading small(ish) files works fine, but larger files can just freeze the program.

What I have found out, is the connection could be timing out after a certain time, I then thought could it be done using FTP - I use FileZilla and that works! - Nope does the same.

Can anyone please give any suggestions - could something to do with sockets work ( I am what you might call a beginner to java!)

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If FileZilla has the same problem, the problem is somewhere in the network. Since the problem is not limited to this one server, that problem can be your network card drivers, network card itself, cable, or anything beyond that. Start locally, by reinstalling / updating the network card drivers, then work your way along the line.
 
Petereyup Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry - FileZilla DOES work - that's what's weird!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic