Hi there!

I developed an audioplayer for Android for our new project which plays
local and online files. It works great on the G1, but somehow often
fails on the Nexus One when streaming MP3s from the Internet -
especially smaller files.

The problem is that I am using the prepareAsync() method and an
OnPreparedListener but somehow onPrepared() is not called sometimes -
especially when the network is slow. So I am creating a MediaPlayer
object, set the OnPreparedListener, call setDataSource() with an URL
in it and call prepareAsync() - but onPrepared() is not called,
leaving the MediaPlayer in the completely useless transient state
"Preparing". And there seems to be no way to catch this failure.

This is the code I used to track down this error:

--- file: TestMediaPlayer.java ---
package de.marcreichelt.android.testmediaplayer;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.util.Log;

public class TestMediaPlayer extends Activity implements
OnPreparedListener {

        private static final String TAG =
TestMediaPlayer.class.getSimpleName();

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                MediaPlayer mp = new MediaPlayer();
                mp.setOnPreparedListener(this);

                try {

                        // Music from World of Goo Soundtrack
                        // see http://kylegabler.com/WorldOfGooSoundtrack/ :-)

                        Log.d(TAG, "mp.setDataSource()");
                        
mp.setDataSource("http://marcreichelt.de/misc/android/test.mp3";);
                        Log.d(TAG, "mp.prepareAsync()");
                        mp.prepareAsync();

                } catch (Exception e) {
                        Log.e(TAG, "", e);
                }

        }

        @Override
        public void onPrepared(MediaPlayer mp) {
                Log.d(TAG, "mp.start()");
                mp.start();
        }

}
--- end of file ---

To test this code I created a new AVD with Google 7 API / Android 2.1
and set the Emulator speed to "GPRS" (important!). I use the Android
1.6 SDK for compiling my project and minSdkVersion is 4.

This is what I get in Logcat:
03-15 20:31:21.354: INFO/ActivityManager(63): Starting activity:
Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10200000
cmp=de.marcreichelt.android.testmediaplayer/.TestMediaPlayer
bnds=[125,446][235,564] }
03-15 20:31:21.424: DEBUG/TestMediaPlayer(213): mp.setDataSource()
03-15 20:31:21.563: DEBUG/TestMediaPlayer(213): mp.prepareAsync()
03-15 20:31:21.839: INFO/ActivityManager(63): Displayed activity
de.marcreichelt.android.testmediaplayer/.TestMediaPlayer: 440 ms
(total 440 ms)
03-15 20:31:21.946: INFO/PlayerDriver(31): buffering (1)

The method onPrepared() is not called, so I am not able to call
start() on the MediaPlayer object.


Can anyone confirm this problem? Is this a bug in the Android 2.1 SDK
(or maybe 2.0.1, too)? And what can I do to solve this?


Thanks in advance & regards
Marc Reichelt   ||   http://www.marcreichelt.de/

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

Reply via email to