Optimisation MediaPlayerService
This commit is contained in:
@@ -26,6 +26,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
@@ -150,6 +151,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
@@ -157,8 +159,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
switch (id){
|
||||
case R.id.refresh:
|
||||
web.clearCache(true);
|
||||
web.reload();
|
||||
Toast.makeText(this, "Rechargement...", Toast.LENGTH_SHORT).show();
|
||||
reStart();
|
||||
//web.reload();
|
||||
//Toast.makeText(this, "Rechargement...", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
|
||||
case R.id.exit:
|
||||
@@ -177,7 +180,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
case R.id.live:
|
||||
lectureAudio("https://live.radiomercure.fr/on-air/live");
|
||||
return true;
|
||||
//Toast.makeText(this, "Vous écoutez Radio Mercure en direct", Toast.LENGTH_SHORT).show();
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
@@ -194,16 +199,21 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void reStart() {
|
||||
Intent intent = getIntent();
|
||||
finish();
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
//Binding this Client to the AudioPlayer Service
|
||||
private ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
||||
MediaPlayerService.LocalBinder binder = (MediaPlayerService.LocalBinder) service;
|
||||
player = binder.getService();
|
||||
serviceBound = true;
|
||||
|
||||
Toast.makeText(MainActivity.this, "Vous écoutez Radio Mercure en direct", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,6 +222,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
};
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
private void lectureAudio(String chemin) {
|
||||
//Check is service is active
|
||||
@@ -220,9 +231,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
playerIntent.putExtra("media",chemin);
|
||||
startService(playerIntent);
|
||||
bindService(playerIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
} else {
|
||||
//Toast.makeText(player, "OK", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, "Lecture", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
onDestroy();
|
||||
reStart();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user