Browse Source

divers

pull/1/head
Samuel Vermeulen 6 months ago
parent
commit
2d1f2aaeb2
  1. 6
      app/src/main/java/fr/svpro/radiomercure/MainActivity.java
  2. 8
      app/src/main/java/fr/svpro/radiomercure/MediaPlayerService.java

6
app/src/main/java/fr/svpro/radiomercure/MainActivity.java

@ -175,7 +175,7 @@ public class MainActivity extends AppCompatActivity {
return true;
case R.id.live:
liveRadio("https://live.radiomercure.fr/on-air/live");
lectureAudio("https://live.radiomercure.fr/on-air/live");
/* Intent playerIntent = new Intent(this, MediaPlayerService.class);
startService(playerIntent);
@ -216,11 +216,11 @@ public class MainActivity extends AppCompatActivity {
}
};
private void liveRadio(String StreamUrl) {
private void lectureAudio(String chemin) {
//Check is service is active
if (!serviceBound) {
Intent playerIntent = new Intent(this, MediaPlayerService.class);
playerIntent.putExtra("stream_url",StreamUrl);
playerIntent.putExtra("media",chemin);
startService(playerIntent);
bindService(playerIntent, serviceConnection, Context.BIND_AUTO_CREATE);
} else {

8
app/src/main/java/fr/svpro/radiomercure/MediaPlayerService.java

@ -88,7 +88,7 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
}
private MediaPlayer mediaPlayer;
private String StreamUrl;
private String fichierMedia;
private void initMediaPlayer() {
mediaPlayer = new MediaPlayer();
@ -105,7 +105,7 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(StreamUrl);
mediaPlayer.setDataSource(fichierMedia);
} catch (IOException e) {
e.printStackTrace();
stopSelf();
@ -148,7 +148,7 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
public int onStartCommand(Intent intent, int flags, int startId) {
try {
//An audio file is passed to the service through putExtra();
StreamUrl = intent.getExtras().getString("stream_url");
fichierMedia = intent.getExtras().getString("media");
} catch (NullPointerException e) {
stopSelf();
}
@ -159,7 +159,7 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
stopSelf();
}*/
if (StreamUrl != null && StreamUrl != "")
if (fichierMedia != null && fichierMedia != "")
initMediaPlayer();
return super.onStartCommand(intent, flags, startId);

Loading…
Cancel
Save