i wanna to download the mp3 files which in the tomcat, and i use a service
and start a thread in the service to download the file.(xml parser works
good, can parse the mp3file) and the errors are :

debug on the emulator or on the my phone, when I click the mp3 which on the
listview, it can work and download the file, but few seconds late it
crashed, and show the outofmemory Error like the picture show. why?
2.when I debug it on the emulator,size of the mp3 file is little bigger
than the real one on the tomcat, and there are some noise on the file which
be download. why?

3.when I debug it on my phone, size of the mp3 file is much bigger than the
real one(maybe twice as much),and the size maybe different each time I
debug it. when I play it, it just sounds like playing more quickly, of
course with some noise.why?

please help me!!!!

this is the ERROR:

11-30 22:01:39.210: E/dalvikvm-heap(23644): Out of memory on a
22149214-byte allocation. 11-30 22:01:39.215: E/AndroidRuntime(23644):
FATAL EXCEPTION: Thread-11 11-30 22:01:39.215: E/AndroidRuntime(23644):
java.lang.OutOfMemoryError 11-30 22:01:39.215: E/AndroidRuntime(23644): at
java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
11-30 22:01:39.215: E/AndroidRuntime(23644): at
java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:153)
11-30 22:01:39.215: E/AndroidRuntime(23644): at
java.lang.StringBuffer.append(StringBuffer.java:219) 11-30 22:01:39.215:
E/AndroidRuntime(23644): at
jackey.download.HttpDownloader.download(HttpDownloader.java:36) 11-30
22:01:39.215: E/AndroidRuntime(23644): at
jackey.MP3Player.service.MP3service$DownloadMP3thread.run(MP3service.java:48)
11-30 22:01:39.215: E/AndroidRuntime(23644): at
java.lang.Thread.run(Thread.java:1019)


  protected void onListItemClick(ListView l, View v, int position, long id)
{
    //获得用户点击的待下载的MP3对象
    MP3Info mp3Info = UpdateList.get(position);

    Log.d("selectedMP3Info", mp3Info.toString());

    //启动一个service下载该MP3对象
    Intent intent = new Intent();
    intent.putExtra("selectedMP3Info", mp3Info);
    intent.setClass(this, MP3service.class);
    startService(intent);
    //stopService(intent);

    super.onListItemClick(l, v, position, id);
}

    public int onStartCommand(Intent intent, int flags, int startId) {
    MP3Info mp3Info = (MP3Info)
intent.getSerializableExtra("selectedMP3Info");

    Log.d("serviceMP3Info", mp3Info.toString());

    DownloadMP3thread downloadThread =new DownloadMP3thread(mp3Info);
    Thread thread = new Thread(downloadThread);
    thread.start();


    return super.onStartCommand(intent, flags, startId);
}

//创建下载MP3线程
class DownloadMP3thread implements Runnable{
    private MP3Info selectedMP3Info = null;

    public DownloadMP3thread(MP3Info mp3Info) {
        this.selectedMP3Info = mp3Info;
    }

    public void run() {
        Log.d("downloadeThread", "in download thread");

        String downURLStr = "http://192.168.1.100:8080/mp3/
"+selectedMP3Info.getMP3Name();
        HttpDownloader httpDownloader = new HttpDownloader();

        int result = httpDownloader.downFile(downURLStr, "JackeyMP3/",
selectedMP3Info.getMP3Name());
        Log.d("result", ""+result);

        String testResult = httpDownloader.download(downURLStr);
        Log.d("testResult", ""+testResult);
    }

}


    public File write2SDFromInput(String path,String fileName,InputStream
input){
    File file = null;
    OutputStream output = null;
    try{
        creatSDDir(path);
        file = creatSDFile(path + fileName);
        output = new FileOutputStream(file);
        byte buffer [] = new byte[4 * 1024];
        while((input.read(buffer)) != -1){
            output.write(buffer);
        }
        output.flush();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        try{
            output.close();
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    return file;
}

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

Reply via email to