I have a three class: MainActivity, MyService, MyPlayer. MainActivity start service, which start AsyncTask and start MyPlayer (MediaPlayer) play method. But problem that I try to start a radio stream, which are loading for a while(5-10 sec), I want to inform listener that stream loading and infrom when stream loaded (public void onPrepared(MediaPlayer mp) method) in a MainActivity's view, but have an error "can't create handler inside thread". How do I can access to mainactivity's view and context (for toast messages). My code chains:
public class MainActivity extends Activity
startService(new Intent(this, MyService.class));
public class MyService extends Service
player = new MyPlayer(ctx);
AsyncTask
protected Void doInBackground(Void... params) {
player.play();
public class MyPlayer implements OnPreparedListener, OnCompletionListener
@Override
public void onPrepared(MediaPlayer mp)
How to get access to MainActivity's view and context from onPrepared?