optimisation
This commit is contained in:
parent
af00ce1d85
commit
0d388cb6e6
@ -2,6 +2,7 @@ package fr.svpro.rsd;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
@ -26,10 +27,21 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
@ -44,8 +56,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
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;
|
||||
@ -67,7 +77,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
bSite = (Button) findViewById(R.id.siteWeb);
|
||||
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
|
||||
@ -158,19 +167,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
} else {
|
||||
bSite.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (cbLecture.isChecked()) {
|
||||
LectureLocale(streamURL);
|
||||
}
|
||||
}
|
||||
});
|
||||
bShare.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, streamURL);
|
||||
startActivity(Intent.createChooser(intent,""));
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.parse(streamURL),"audio/*");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
bSite.setOnClickListener(new View.OnClickListener() {
|
||||
@ -187,29 +191,37 @@ 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;
|
||||
private void disableSSLCertificateChecking() {
|
||||
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String s, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
mp.start();
|
||||
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {// Not implemented
|
||||
}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {// Not implemented
|
||||
}
|
||||
} };
|
||||
|
||||
try {
|
||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
mediaPlayer.setDataSource(urlStation);
|
||||
mediaPlayer.prepareAsync();
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalStateException e) {
|
||||
} catch (IOException e) {
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,14 +90,6 @@
|
||||
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user