Buttons that do not work

0

I have this radio project but I can not make the radio operation buttons work (play, pause, stop and reload). Interestingly the other buttons of my Main Activity work perfectly and the program works

I leave here my code:

public class MainActivity extends Activity {
ImageButton btnPlay;
ImageButton btnRec;
ImageButton btnStp;
ImageButton btnSal;
Button btnMul;
Button btnRa;
Button btnNos;

MediaPlayer mediaplayer;
String stream="http://streams.calmradio.com/api/67/128/stream/;";
boolean prepared,started=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnPlay=(ImageButton)findViewById(R.id.play);
    btnRec=(ImageButton)findViewById(R.id.reconectar);
    btnStp=(ImageButton)findViewById(R.id.parar);
    btnSal=(ImageButton)findViewById(R.id.salir);
    btnMul=(Button)findViewById(R.id.multimedia);
    btnRa=(Button)findViewById(R.id.radio);
    btnNos=(Button)findViewById(R.id.nosotros);

    final Toast toast=Toast.makeText(getApplicationContext(),"Esperando respúesta del Servidor...",Toast.LENGTH_LONG);
    toast.show();
    btnPlay.setEnabled(false);
    btnRec.setEnabled(false);
    btnStp.setEnabled(false);

    mediaplayer=new MediaPlayer();
    mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    new PlayerTask().execute(stream);

  //botones Radio
    btnPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (started){
                started=false;
                mediaplayer.pause();
                btnPlay.setBackgroundResource(R.drawable.play);
                Toast toast=Toast.makeText(getApplicationContext(),"Pausa",Toast.LENGTH_SHORT);
                toast.show();
            }else{
                started=true;
                mediaplayer.start();
                btnPlay.setBackgroundResource(R.drawable.pause);
                Toast toast=Toast.makeText(getApplicationContext(),"Play",Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    });

    btnStp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaplayer.stop();
            Toast toast=Toast.makeText(getApplicationContext(),"Stop",Toast.LENGTH_SHORT);
            toast.show();
        }
    });
    btnRec.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaplayer.stop();
            Intent Recargar =getIntent();
            finish();
            startActivity(Recargar );
        }
    });

    //Botones Navegacion
    btnSal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mediaplayer.release();
            System.exit(0);
        }
    });

    btnNos.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent Nosotros=new Intent(getApplicationContext(),Nosotros.class);
            startActivity(Nosotros);
            mediaplayer.stop();

        }
    });

    btnMul.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent Multimedia=new Intent(getApplicationContext(),Multimedia.class);
            startActivity(Multimedia);
            mediaplayer.stop();
        }
    });



}

 class PlayerTask extends AsyncTask<String,Void,Boolean>{


    protected Boolean doInBackground(String...String){
        try{
            mediaplayer.setDataSource(String[0]);
            mediaplayer.prepare();
            prepared=true;
        }catch(IOException e){
            e.printStackTrace();
        }
        return prepared;
    }

    @Override
    protected void onPostExecute(Boolean aBoolean){

        super.onPostExecute(aBoolean);
        mediaplayer.start();

    }

}
}

I also leave the contents of the Logcat

09-11 20:19:43.100 16075-16075/? I/art: Late-enabling -Xcheck:jni
09-11 20:19:43.259 16075-16075/com.example.eliseo.radio W/System: ClassLoader referenced unknown path: /data/app/com.example.eliseo.radio-2/lib/arm
09-11 20:19:43.270 16075-16075/com.example.eliseo.radio I/InstantRun: starting instant run server: is main process
09-11 20:19:43.635 16075-16089/com.example.eliseo.radio I/MediaHTTPConnection: proxyName: 0.0.0.0 0
09-11 20:19:43.636 16075-16089/com.example.eliseo.radio D/NetworkSecurityConfig: No Network Security Config specified, using platform default
09-11 20:19:43.705 16075-16180/com.example.eliseo.radio I/Adreno: QUALCOMM build                   : bc479b6, I15255e4b4a
Build Date                       : 02/22/17
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch                     : 
Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.00.00.269.019
Remote Branch                    : NONE
Reconstruct Branch               : NOTHING
09-11 20:19:43.710 16075-16180/com.example.eliseo.radio I/OpenGLRenderer: 
Initialized EGL, version 1.4
09-11 20:19:43.710 16075-16180/com.example.eliseo.radio D/OpenGLRenderer: Swap behavior 1
09-11 20:19:47.391 16075-16177/com.example.eliseo.radio D/MediaPlayer: 
setSubtitleAnchor in MediaPlayer
09-11 20:19:47.391 16075-16075/com.example.eliseo.radio D/MediaPlayer: setSubtitleAnchor in MediaPlayer

To simplify, the only highlight of this is

  

W / System: ClassLoader referenced unknown path: /data/app/com.example.eliseo.radio-2/lib/arm

But the truth is I do not have much experience and I do not know if this is the problem.From now on Thanks for helping

here I add the activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">


<ImageView
    android:id="@+id/base"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/todo"
    android:scaleType="fitXY"
    android:src="@drawable/fondo" />

<Button
    android:id="@+id/nosotros"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="@string/nosotros"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.105"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/multimedia"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/multimedia"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.262"
    app:layout_constraintStart_toEndOf="@+id/nosotros"
    app:layout_constraintTop_toTopOf="parent" />

<ImageButton
    android:id="@+id/play"
    android:layout_width="82dp"
    android:layout_height="50dp"
    android:layout_marginBottom="36dp"
    android:contentDescription="@string/Play"
    android:src="@drawable/play"
    app:layout_constraintBottom_toBottomOf="@+id/base"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<ImageButton
    android:id="@+id/reconectar"
    android:layout_width="82dp"
    android:layout_height="50dp"
    android:layout_marginBottom="36dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:src="@android:drawable/ic_menu_rotate"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/play"
    app:layout_constraintStart_toStartOf="parent"
    android:contentDescription="@string/Recargar" />

<ImageButton
    android:id="@+id/parar"
    android:layout_width="82dp"
    android:layout_height="50dp"
    android:layout_marginBottom="36dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:contentDescription="@string/Stop"
    android:src="@android:drawable/ic_lock_power_off"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/play" />

<ImageButton
    android:id="@+id/salir"
    android:layout_width="42dp"
    android:layout_height="40dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginTop="8dp"
    android:contentDescription="@string/Salir"
    android:src="@android:drawable/ic_notification_clear_all"
    app:layout_constraintBottom_toTopOf="@+id/multimedia"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

</android.support.constraint.ConstraintLayout>
    
asked by Eliseo Baroni 12.09.2018 в 01:27
source

1 answer

0

The problem was in

btnPlay.setEnabled(false);
btnStp.setEnabled(false);
btnRec.setEnabled(false);
    
answered by 16.09.2018 / 22:01
source