Browse Source

divers

pull/1/head
Samuel Vermeulen 6 months ago
parent
commit
7bfb2f0f66
  1. 11
      app/src/main/java/fr/svpro/radiomercure/MainActivity.java
  2. 16
      app/src/main/java/fr/svpro/radiomercure/MediaPlayerService.java

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

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -33,7 +34,6 @@ public class MainActivity extends AppCompatActivity {
private static final int WRITE_EXTERNAL_STORAGE_RC = 100;
private WebView web;
private String url, userAgent, contentDisposition, mimeType;
private Menu menu;
private Dialog dialog;
private TextView tv_close;
private TextView tv_version;
@ -150,6 +150,7 @@ public class MainActivity extends AppCompatActivity {
return super.onCreateOptionsMenu(menu);
}
@SuppressLint("UseCompatLoadingForDrawables")
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
@ -176,11 +177,6 @@ public class MainActivity extends AppCompatActivity {
case R.id.live:
lectureAudio("https://live.radiomercure.fr/on-air/live");
/* Intent playerIntent = new Intent(this, MediaPlayerService.class);
startService(playerIntent);
bindService(playerIntent, serviceConnection, Context.BIND_AUTO_CREATE);*/
return true;
default:
@ -216,6 +212,7 @@ public class MainActivity extends AppCompatActivity {
}
};
@SuppressLint("UseCompatLoadingForDrawables")
private void lectureAudio(String chemin) {
//Check is service is active
if (!serviceBound) {
@ -223,7 +220,7 @@ public class MainActivity extends AppCompatActivity {
playerIntent.putExtra("media",chemin);
startService(playerIntent);
bindService(playerIntent, serviceConnection, Context.BIND_AUTO_CREATE);
} else {
} else {
//Toast.makeText(player, "OK", Toast.LENGTH_SHORT).show();
}
}

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

@ -1,25 +1,34 @@
package fr.svpro.radiomercure;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import java.io.IOException;
@RequiresApi(api = Build.VERSION_CODES.O)
public class MediaPlayerService extends Service implements MediaPlayer.OnCompletionListener,
MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnSeekCompleteListener,
MediaPlayer.OnInfoListener, MediaPlayer.OnBufferingUpdateListener,
AudioManager.OnAudioFocusChangeListener {
// Binder given to clients
private final IBinder iBinder = new LocalBinder();
@ -48,12 +57,15 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
//Invoked when there has been an error during an asynchronous operation
switch (what) {
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
Toast.makeText(this, "Données corrompues", Toast.LENGTH_SHORT).show();
Log.d("MediaPlayer Error", "MEDIA ERROR NOT VALID FOR PROGRESSIVE PLAYBACK " + extra);
break;
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
Toast.makeText(this, "Serveur innacessible", Toast.LENGTH_SHORT).show();
Log.d("MediaPlayer Error", "MEDIA ERROR SERVER DIED " + extra);
break;
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
Toast.makeText(this, "Erreur inconnue", Toast.LENGTH_SHORT).show();
Log.d("MediaPlayer Error", "MEDIA ERROR UNKNOWN " + extra);
break;
}
@ -214,6 +226,4 @@ public class MediaPlayerService extends Service implements MediaPlayer.OnComplet
telephonyManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
}
Loading…
Cancel
Save