I am seeing a memory/resource leak after 3-4 hours of media play under
the following conditions:
    1. Android 1.6
    2. OTA (over-the-air) streaming.
    3. AAC v1 or AAC v2 content.

If any of those variables change, I do not see the issue -- i.e.
Android 1.5 and 2.0 do not have this problem, WiFi streaming or local
file playback does not have this problem, streaming MP3 content does
not have this problem.

I have created a "hello world" test application which exhibits this
problem.  The only purpose of this test application is to demonstrate
this problem (not coding style / error checking, etc...).  After
approximately 3-4 hours of playback, the phone (T-Mobile G1 or G2)
becomes very sluggish and even simple things like hitting the "home"
button can take a very long time.

Any help *greatly* appreciated.

tia.

package com.test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class TestPlayer extends Activity implements OnErrorListener,
OnBufferingUpdateListener, OnCompletionListener {
        private MediaPlayer mp = new MediaPlayer();
        private File allFiles[] = null;
        private ArrayList<String> files = new ArrayList<String>();
        private Random random = null;
        private int index = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String now = new Date(System.currentTimeMillis()).toString();
        ((TextView) findViewById(R.id.textWindow)).append("Start Date: "
+ now + "\n");

        files.add("http://some-random-aacv1orv2audiofile...";);
        files.add("http://some-random-aacv1orv2audiofile...";);
        files.add("http://some-random-aacv1orv2audiofile...";);
        files.add("http://some-random-aacv1orv2audiofile...";);

        random = new Random(System.currentTimeMillis());

        int mm = files.size();
        for (int jj = 0; jj < mm; jj++) {
                Log.i("test", "file: " + files.get(jj));
        }

        try {
                mp = new MediaPlayer();
                mp.reset();

                int rr = random.nextInt();
                int ii = (rr < 0 ? -rr : rr) % files.size();
                String path = files.get(ii);
                Log.i("onCreate", "Path: " + path);
                ((TextView) findViewById(R.id.textWindow)).append(index + ",
" + path + "\n");
                index++;
                mp.setDataSource(path);

                mp.prepare();
                mp.start();
                mp.setOnErrorListener(this);
                mp.setOnBufferingUpdateListener(this);
                mp.setOnCompletionListener(this);
        } catch (Exception e) {
                Log.e("test", "exception in media player!");
                e.printStackTrace();
        }
    }

        // OnErrorListener
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e("onError", "what: " + what + ", extra: " + extra);
                return false;
        }

        // OnBufferingUpdateListener
        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
                Log.i("onBufferingUpdate", "percent: " + percent);
        }

        // OnCompletionListener
        @Override
        public void onCompletion(MediaPlayer mp) {
                try {
                        Log.i("onCompletion", "onCompletion");

                        mp.reset();
                        mp.release();
                        mp = null;

                        mp = new MediaPlayer();
                        mp.reset();

                        int rr = random.nextInt();
                        int ii = (rr < 0 ? -rr : rr) % files.size();
                        String path = files.get(ii);
                        Log.i("onCompletion", "Path: " + path);
                        ((TextView) findViewById(R.id.textWindow)).append(index 
+ ",
" + path + "\n");
                        index++;
                        mp.setDataSource(path);

                        mp.prepare();
                        mp.start();
                        mp.setOnErrorListener(this);
                        mp.setOnBufferingUpdateListener(this);
                        mp.setOnCompletionListener(this);

                } catch (Exception e) {
                        Log.e("test", "exception in media player!");
                        e.printStackTrace();
                }
        }
}

-- 
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