Ajout MediaPlyer
This commit is contained in:
parent
6ad6880a93
commit
af00ce1d85
@ -2,14 +2,19 @@ package fr.svpro.rsd;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -34,14 +39,17 @@ import okhttp3.Response;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private final static String URL = "https://radiobrowser.weblib.re/json/stations/byname/";
|
||||
private final static String URL = "https://radiobrowser.weblib.re/json/stations";
|
||||
private ListView listView;
|
||||
private EditText etRecherche;
|
||||
private Button bRecherche, bShare, bSite;
|
||||
public RadioButton rechNom, rechPays;
|
||||
public CheckBox cbLecture;
|
||||
private TextView resultat;
|
||||
public String siteWeb;
|
||||
private String nomStation;
|
||||
private String streamURL;
|
||||
private String byFiltre;
|
||||
ArrayList<HashMap<String, String>> arrayList;
|
||||
|
||||
|
||||
@ -57,7 +65,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
bRecherche = (Button) findViewById(R.id.recherche);
|
||||
bShare = (Button) findViewById(R.id.share);
|
||||
bSite = (Button) findViewById(R.id.siteWeb);
|
||||
//resultat = (TextView) findViewById(R.id.resultText);
|
||||
rechNom = (RadioButton) findViewById(R.id.rech_nom);
|
||||
rechPays = (RadioButton) findViewById(R.id.rech_pays);
|
||||
cbLecture = (CheckBox) findViewById(R.id.cbLecture);
|
||||
|
||||
bRecherche.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -68,13 +78,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
parse();
|
||||
}
|
||||
});
|
||||
//Initialisation filtre recherche
|
||||
if (rechNom.isChecked()) {
|
||||
setTitle("Rechercher par nom");
|
||||
byFiltre = "/byname/";
|
||||
}
|
||||
//
|
||||
rechNom.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setTitle("Rechercher par nom");
|
||||
byFiltre = "/byname/";
|
||||
}
|
||||
});
|
||||
|
||||
rechPays.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setTitle("Rechercher par pays");
|
||||
byFiltre = "/bycountry/";
|
||||
}
|
||||
});
|
||||
}
|
||||
public void parse(){
|
||||
arrayList = new ArrayList<>();
|
||||
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(URL + etRecherche.getText() + "?hidebroken=true")
|
||||
.url(URL + byFiltre + etRecherche.getText() + "?hidebroken=true")
|
||||
.build();
|
||||
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@ -127,6 +158,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
bSite.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (cbLecture.isChecked()) {
|
||||
LectureLocale(streamURL);
|
||||
}
|
||||
}
|
||||
});
|
||||
bShare.setOnClickListener(new View.OnClickListener() {
|
||||
@ -152,30 +186,31 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public void LectureLocale(String urlStation) {
|
||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
|
||||
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
mp.reset();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
mp.start();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
mediaPlayer.setDataSource(urlStation);
|
||||
mediaPlayer.prepareAsync();
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalStateException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/* public ListView getListView() {
|
||||
return listView;
|
||||
}
|
||||
|
||||
public EditText getEtRecherche() {
|
||||
return etRecherche;
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return bRecherche;
|
||||
}
|
||||
|
||||
public TextView getResultat() {
|
||||
return resultat;
|
||||
}
|
||||
|
||||
public String getPageWeb() {
|
||||
return pageWeb;
|
||||
}
|
||||
|
||||
public ArrayList<HashMap<String, String>> getArrayList() {
|
||||
return arrayList;
|
||||
}*/
|
||||
}
|
@ -5,58 +5,106 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="MissingConstraints">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etRecherche"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints=""
|
||||
android:ems="10"
|
||||
android:hint="Nom"
|
||||
android:inputType="textPersonName"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/recherche"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rechercher..." />
|
||||
|
||||
<Button
|
||||
android:id="@+id/share"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Partager..."
|
||||
android:visibility="invisible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/siteWeb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Site WEB..."
|
||||
android:visibility="invisible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="50dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listView"
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="MissingConstraints">
|
||||
|
||||
</ListView>
|
||||
<EditText
|
||||
android:id="@+id/etRecherche"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints=""
|
||||
android:ems="10"
|
||||
android:hint="Nom"
|
||||
android:inputType="textPersonName"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/recherche"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rechercher..." />
|
||||
|
||||
<Button
|
||||
android:id="@+id/share"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Partager..."
|
||||
android:visibility="invisible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/siteWeb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Site WEB..."
|
||||
android:visibility="invisible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rechercher par : "
|
||||
android:textStyle="bold">
|
||||
|
||||
</TextView>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rech_nom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="Nom" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rech_pays"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Pays" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/cbLecture"
|
||||
android:text="Lecture locale">
|
||||
|
||||
</CheckBox>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</ListView>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">JsonTest</string>
|
||||
<string name="app_name">RadioStreamData</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user