[android-developers] Re: Save an mp3 from a remote site

2009-03-31 Thread MrChaz

Sure,
Something like

//Where the file comes from
URL sourceURL = new URL(address);
URLConnection conn = sourceURL.openConnection();

InputStream inStream = sourceURL.openStream();

// Where the file is going to go
FileOutputStream outStream= new FileOutputStream(sdcard/file.mp3);

//a read buffer
byte[] bytes = new byte[20480];

//read the first chunk
int readBytes = file.read(bytes);

//read the rest
while (readBytes  0){
 //Write the buffered chunk to the file
 outStream.write(bytes, 0, readBytes);
 readBytes = file.read(bytes);
}
inStream.close();
outStream.close();

should do it.  I've typed that more or less by hand so it's missing
error checking etc.

On Mar 31, 8:10 am, idev ideveloper...@gmail.com wrote:
 Hi

 I am able to stream an mp3 at real time on my android phone. I wanted
 to know if it is possible to save an mp3 file residing on a remote
 location to my SD card.

 Any heads up is greatly appreciated.

 Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Save an mp3 from a remote site

2009-03-31 Thread iDeveloper

Thanks a ton. Didn't know android allowed saving to mp3 directly  
unlike an iphone.



On 31-Mar-09, at 5:32 PM, MrChaz wrote:


 Sure,
 Something like

 //Where the file comes from
 URL sourceURL = new URL(address);
 URLConnection conn = sourceURL.openConnection();

 InputStream inStream = sourceURL.openStream();

 // Where the file is going to go
 FileOutputStream outStream= new FileOutputStream(sdcard/file.mp3);

 //a read buffer
 byte[] bytes = new byte[20480];

 //read the first chunk
 int readBytes = file.read(bytes);

 //read the rest
 while (readBytes  0){
 //Write the buffered chunk to the file
 outStream.write(bytes, 0, readBytes);
 readBytes = file.read(bytes);
 }
 inStream.close();
 outStream.close();

 should do it.  I've typed that more or less by hand so it's missing
 error checking etc.

 On Mar 31, 8:10 am, idev ideveloper...@gmail.com wrote:
 Hi

 I am able to stream an mp3 at real time on my android phone. I wanted
 to know if it is possible to save an mp3 file residing on a remote
 location to my SD card.

 Any heads up is greatly appreciated.

 Thanks.
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Save an mp3 from a remote site

2009-03-31 Thread Streets Of Boston

This is just copying the file.
The question remains if you can play it or not... :=)

I have not looked into this at all, but DRM could prevent the mp3 from
playing.

On Mar 31, 9:55 am, iDeveloper ideveloper...@gmail.com wrote:
 Thanks a ton. Didn't know android allowed saving to mp3 directly  
 unlike an iphone.

 On 31-Mar-09, at 5:32 PM, MrChaz wrote:





  Sure,
  Something like

  //Where the file comes from
  URL sourceURL = new URL(address);
  URLConnection conn = sourceURL.openConnection();

  InputStream inStream = sourceURL.openStream();

  // Where the file is going to go
  FileOutputStream outStream= new FileOutputStream(sdcard/file.mp3);

  //a read buffer
  byte[] bytes = new byte[20480];

  //read the first chunk
  int readBytes = file.read(bytes);

  //read the rest
  while (readBytes  0){
  //Write the buffered chunk to the file
  outStream.write(bytes, 0, readBytes);
  readBytes = file.read(bytes);
  }
  inStream.close();
  outStream.close();

  should do it.  I've typed that more or less by hand so it's missing
  error checking etc.

  On Mar 31, 8:10 am, idev ideveloper...@gmail.com wrote:
  Hi

  I am able to stream an mp3 at real time on my android phone. I wanted
  to know if it is possible to save an mp3 file residing on a remote
  location to my SD card.

  Any heads up is greatly appreciated.

  Thanks.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Save an mp3 from a remote site

2009-03-31 Thread Jean-Baptiste Queru

No problem playing an MP3 from the SD card. You should be able to
ACTION_VIEW the file:/// URI directly, or invoke the media scanner on
it and ACTION_VIEW the resulting content:// URI (added bonus for the
second method is that the file will immediately show up in the music
player as well).

JBQ

On Tue, Mar 31, 2009 at 7:08 AM, Streets Of Boston
flyingdutc...@gmail.com wrote:

 This is just copying the file.
 The question remains if you can play it or not... :=)

 I have not looked into this at all, but DRM could prevent the mp3 from
 playing.

 On Mar 31, 9:55 am, iDeveloper ideveloper...@gmail.com wrote:
 Thanks a ton. Didn't know android allowed saving to mp3 directly
 unlike an iphone.

 On 31-Mar-09, at 5:32 PM, MrChaz wrote:





  Sure,
  Something like

  //Where the file comes from
  URL sourceURL = new URL(address);
  URLConnection conn = sourceURL.openConnection();

  InputStream inStream = sourceURL.openStream();

  // Where the file is going to go
  FileOutputStream outStream= new FileOutputStream(sdcard/file.mp3);

  //a read buffer
  byte[] bytes = new byte[20480];

  //read the first chunk
  int readBytes = file.read(bytes);

  //read the rest
  while (readBytes  0){
  //Write the buffered chunk to the file
  outStream.write(bytes, 0, readBytes);
  readBytes = file.read(bytes);
  }
  inStream.close();
  outStream.close();

  should do it.  I've typed that more or less by hand so it's missing
  error checking etc.

  On Mar 31, 8:10 am, idev ideveloper...@gmail.com wrote:
  Hi

  I am able to stream an mp3 at real time on my android phone. I wanted
  to know if it is possible to save an mp3 file residing on a remote
  location to my SD card.

  Any heads up is greatly appreciated.

  Thanks.- Hide quoted text -

 - Show quoted text -
 




-- 
Jean-Baptiste M. JBQ Queru
Android Engineer, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Save an mp3 from a remote site

2009-03-31 Thread MrChaz

Good point, I forgot about the MediaScanner.
One thing to note about using ACTION_VIEW is although you get the nice
mediaplayer UI it doesn't keep playing when you change Activities e.g.
go back to the home screen.

On Mar 31, 3:57 pm, Jean-Baptiste Queru j...@android.com wrote:
 No problem playing an MP3 from the SD card. You should be able to
 ACTION_VIEW the file:/// URI directly, or invoke the media scanner on
 it and ACTION_VIEW the resulting content:// URI (added bonus for the
 second method is that the file will immediately show up in the music
 player as well).

 JBQ

 On Tue, Mar 31, 2009 at 7:08 AM, Streets Of Boston



 flyingdutc...@gmail.com wrote:

  This is just copying the file.
  The question remains if you can play it or not... :=)

  I have not looked into this at all, but DRM could prevent the mp3 from
  playing.

  On Mar 31, 9:55 am, iDeveloper ideveloper...@gmail.com wrote:
  Thanks a ton. Didn't know android allowed saving to mp3 directly
  unlike an iphone.

  On 31-Mar-09, at 5:32 PM, MrChaz wrote:

   Sure,
   Something like

   //Where the file comes from
   URL sourceURL = new URL(address);
   URLConnection conn = sourceURL.openConnection();

   InputStream inStream = sourceURL.openStream();

   // Where the file is going to go
   FileOutputStream outStream= new FileOutputStream(sdcard/file.mp3);

   //a read buffer
   byte[] bytes = new byte[20480];

   //read the first chunk
   int readBytes = file.read(bytes);

   //read the rest
   while (readBytes  0){
   //Write the buffered chunk to the file
   outStream.write(bytes, 0, readBytes);
   readBytes = file.read(bytes);
   }
   inStream.close();
   outStream.close();

   should do it.  I've typed that more or less by hand so it's missing
   error checking etc.

   On Mar 31, 8:10 am, idev ideveloper...@gmail.com wrote:
   Hi

   I am able to stream an mp3 at real time on my android phone. I wanted
   to know if it is possible to save an mp3 file residing on a remote
   location to my SD card.

   Any heads up is greatly appreciated.

   Thanks.- Hide quoted text -

  - Show quoted text -

 --
 Jean-Baptiste M. JBQ Queru
 Android Engineer, Google.

 Questions sent directly to me that have no reason for being private
 will likely get ignored or forwarded to a public forum with no further
 warning.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---