0
votes

I have 2 activities and a static mediaplayer in my first activity I prepare and start the media player and jump to other activity. In the second activity I can pause and play this media player when I press back button on the second activity it goes to the first activity and than stop media player and than release media player but mp.release gives me "has stopped unexpectedly error". Can you help me please? I need to make this mp.release() work

 new AsyncTask<Void, Double, Void>() {

        @Override
        protected Void doInBackground(Void... params) {

            while (true) {
                publishProgress(Math.random());
                SystemClock.sleep(3000);

                if(isOnline(Start.this) == true && connection == true){
                    LinkedList<String> urls = readM3UtoUrlList("url.m3u");

                    mp = new MediaPlayer();
                    try {
                        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);    
                        mp.setDataSource(urls.getFirst());
                        mp.setOnPreparedListener(new OnPreparedListener() {
                            @Override
                            public void onPrepared(MediaPlayer mp) {
                                Intent i = new Intent(Start.this, RadyoBabylonActivity.class);
                                startActivityForResult(i, RadyoBabylonActivity.class.hashCode());
                            }
                        });

                        mp.prepare();
                        mp.start();


                    } catch (Exception e) {

                        e.printStackTrace();
                    } 
                }
            }

        }

        @Override
        protected void onProgressUpdate(Double... values) {


            }
        }
    }.execute();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode==-1){
        Log.d("myerror", "kapanacavk");
        mp.stop();

        if(!mp.isPlaying())
        {
            mp.release();
            finish();
        }


    }
}

log

ERROR/AndroidRuntime(7480): FATAL EXCEPTION: main
ERROR/AndroidRuntime(7480): java.lang.IllegalStateException
ERROR/AndroidRuntime(7480):     at android.media.MediaPlayer.isPlaying(Native Method)
ERROR/AndroidRuntime(7480):     at com.radyobabylon.RadyoBabylonActivity$2.onProgressUpdate(RadyoBabylonActivity.java:189)
ERROR/AndroidRuntime(7480):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432)
ERROR/AndroidRuntime(7582):     at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(7582):     at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(7582):     at android.app.ActivityThread.main(ActivityThread.java:4627)
ERROR/AndroidRuntime(7582):     at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(7582):     at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(7582):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
ERROR/AndroidRuntime(7582):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
ERROR/AndroidRuntime(7582):     at dalvik.system.NativeStart.main(Native Method)
1
Add the LogCat output... - Lukas Knuth

1 Answers

1
votes

I think you need to stop your progress update loop before releasing the mediaplayer object as you are not allowed to call isPlaying() on a released mediaplayer see here for the list of valid states