×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    download mp3 files from a remote server to mobile file system

    Could you please help me to :
    • find some Java sample source code to download a remote mp3 file to a Nokia mobile?
    • find the necessary J2ME libraries (or functions) to download a remote mp3 file to a Nokia mobile?

    My aim is to download the mp3 files without using the mobile browser i.e. I'd like to stay into my application during the download process.

    Thanks in advance

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: download mp3 files from a remote server to mobile file system

    See this article.

    EDIT: My mistake, I understood that you wanted to download the file and play it.

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: download mp3 files from a remote server to mobile file system

    Hi jetmaroc,

    welcome to Forum Nokia Discussion Boards!

    To download and save data from network to device filesystem, you will need 2 things:

    * establish an HttpConnection (here's an HttpConnection usage example) to physically download data from network
    * use FileConnection API to save downloaded data on device filesystem

    Note however that FileConnection is an optional API, so it is not supported by all devices.

    Pit

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    Re: download mp3 files from a remote server to mobile file system

    Hello jappit!

    Thanks u so much for your help!
    I tested the HttpConnection usage example and it works very well but only if my remote mp3 file's size is smaller than 1Mb (1024Kb).
    As soon as I invoke a mp3 file with a size bigger (for instance 2Mb), I catch a Out of Memory exception...

    Can you please help me to solve this other issue?

    Thanks u so much in advance!

    jetmaroc

  5. #5
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: download mp3 files from a remote server to mobile file system

    It seems there is a memory problem. Can you tell me the memory which is available in your memory ? If it is possible to insert memory card in device then insert it and test it again ? See also device specification of the devcice which you are using.

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    48

    Re: download mp3 files from a remote server to mobile file system

    Use an InputStream and an OutputStream and write as it downloads every chunk and you shouldn't get an out of memory error for the app.

    e.g.

    Code:
    while ((c= iStrm.read()) != -1){
                    oStrm.write(c);
     
                }
    If you run out of disk space this could be a different problem.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    Re: download mp3 files from a remote server to mobile file system

    Hello sinkers!

    Thanks you for your suggestion. I no longer have an Out of memory error but now I get an IO Exception (i.e. Error in HTTP operation). This error is precisely thrown by the instruction with the red font in the code below as soon as I try to download a mp3 file which size is bigger than 1Mb.
    Could you please tell me if you have any idea about this new matter?

    Code:
    public void downloadSound(String mp3Url){
        HttpConnection httpConn = null;
        InputStream iStrm = null;
        int c = 0;
        try{
                httpConn = (HttpConnection)Connector.open(mp3Url);                 
                try{
                    iStrm = httpConn.openInputStream(); 
                }catch(IOException ioe){
                    displayAlertMsg("IO Exception 1 : " + ioe.toString()) ;
                }  
                
                FileConnection filecon = (FileConnection) Connector.open(dirToSave + nomadSubdir + filename, Connector.READ_WRITE);
                
                if(!filecon.exists()) {
                     filecon.create();
                }            
                
                OutputStream oStrm = filecon.openOutputStream();
    
                while ((c= iStrm.read()) != -1){
                    oStrm.write(c);
                } 
               
                oStrm.close(); 
                filecon.close();
                displayAlertMsg("Download done successfully.");
    
        }catch(OutOfMemoryError ofm){
             displayAlertMsg("Out of memory Exception :" + ofm.toString());
        }catch(IOException ioe){
             displayAlertMsg("IO Exception 2 : " + ioe.toString());
        }catch(Exception e){
             displayAlertMsg("Exception :" + e.toString());
        }  
    
        finally{                        
            try{
                if(iStrm != null)
                    iStrm.close();
            } catch(Throwable t){
                System.out.println("Exception occurred while closing input stream : "+t.toString());
            }
            try{
                if(httpConn != null)
                    httpConn.close();                        
            } catch(Throwable t){
                System.out.println("Exception occurred : "+t.toString());
            }
        }
    }

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    48

    Re: download mp3 files from a remote server to mobile file system

    Are you testing in the emulator or on a phone? If phone which one?

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    12

    Re: download mp3 files from a remote server to mobile file system

    The error occurs in a phone, a Nokia 6300

    In the emulator integrated to Netbeans 6.1 or in the Wireless Toolkit 2.5.2, I have no error even if I download a 11Mb mp3 file for instance.

    Regards

  10. #10
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Re: download mp3 files from a remote server to mobile file system

    Hello,

    I m using the same logic to download an MP3 file from remote server but my application exits on device when i check for more than 1MB of data but its working fine for less data size than 1MB. When application get exits automatically in case of downloading more than 1MB of data and when i chk for downloaded file it shows its size less than total size and when i try to play it says can not play this file. i m writing data to file parts.

    please help me out in finding what could be the problem.
    Last edited by mkstar; 2009-09-02 at 14:20.

  11. #11
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Re: download mp3 files from a remote server to mobile file system

    Hello sinkers!

    I think my problem is same that jetmaroc is facing.

    I am getting IOException : unexpected end of stream exception while trying to download more than 1MB of data.

    I am using GET as HttpRequest method.

Similar Threads

  1. Is there anybody know file system filter in S60_3rd?
    By zhangwei_Nirvana in forum Symbian
    Replies: 5
    Last Post: 2008-04-26, 07:06
  2. Mobile Virus Info and Solution
    By kunalshastry in forum General Development Questions
    Replies: 16
    Last Post: 2007-08-07, 11:12
  3. File server: Compilation error in carbide.c++
    By justteam in forum Symbian
    Replies: 6
    Last Post: 2007-01-03, 23:44
  4. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •