I'm trying to make a Internet Audio Player for my Xperia SP but I want to add my own user-agent

Viewed 12

Hello stackoverslow users! I'm trying to make a Internet Audio Player of my radio Musicas Por Lukas and I did the code but when I try to play the radio in my Xperia SP, it cannot play the audio and I tried to check the code error but I only get warnings. I also want to add my user-agent. Also when you are done fixing the problem, make sure to keep the code look more neat like this,

<element1>
 <element2>
  <tags1>text1</tags1>
 <element2/>
 <element3>
  <tags2 info1="text2"/>
  <element4>
   <element5>
    <tags3>text3</tags3>
   </element5>
  </element4>
 </element3>
</element1>

Please fix my code also add the user-agent, my own user agent will be like this: Musicas Por Lukas Listener (with the device info like the os (operating system) of the phone and the company that made the phone)

package com.musicasporlukas.lukasito2011;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
 private Button button_stop;
 private Button button_play;
 private String STREAM_URL = "http://51.255.235.165:22583/stream_mp3";
 private MediaPlayer mPlayer;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  button_stop = (Button)  findViewById(R.id.button_stop);
  button_play = (Button)  findViewById(R.id.button_play);
  mPlayer = new MediaPlayer();
  button_play.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    try {
     mPlayer.reset();
     mPlayer.setDataSource(STREAM_URL);
     mPlayer.prepareAsync();
     mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mp) {
       mp.start();
      }
     });
    }
    catch (IOException e) {
     e.printStackTrace();
    }
   }
  });
  button_play.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    mPlayer.stop();
   }
  });
 }
}

Please fix it.

0 Answers
Related