iammert / RadioPlayerService

Android service library which uses AAC Player. Ready to use Radio Player Service.
254 stars 90 forks source link

Problem with listeners #47

Open suman-tms opened 7 years ago

suman-tms commented 7 years ago

When i add some code after listener the radio wont play. Like when i try to do something like add a toast messge inside onMetaDataReceived. The app doesnt play anything and when i remove it. It works fine. Can someone help me.

public class MainActivity extends Activity implements RadioListener ... @Override public void onRadioStarted() {

}

@Override
public void onRadioStopped() {

}

@Override
public void onMetaDataReceived(String s, String s1) {

}
anaszakariyah commented 7 years ago

The radio seems to break whenever you try to do anything with View inside the listener. I don't know why. Updating variable is ok, but doing changes on your view will break it. EDIT: maybe the listener cannot run on ui thread..

willsazon commented 7 years ago

This is how it was here.

   **@Override
    public void onRadioStarted() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                nomeMusica.setText("Reproduzindo Áudio...");
                findViewById(R.id.iv_player).setBackgroundResource(R.drawable.action_pause);
            }
        });
    }**