Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
Trying again to fix Android Auto crashing. I believe this'll work.
  • Loading branch information
Carlos Perez committed Jul 9, 2022
1 parent bf31cb6 commit d9d2f9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
25 changes: 13 additions & 12 deletions android/app/src/main/java/tech/logica10/soniclair/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Globals{
public class Globals {
// Static variable reference of single_instance
// of type Singleton
private static Globals single_instance = null;
Expand All @@ -20,49 +21,49 @@ public class Globals{
// Constructor
// Here we will be creating private constructor
// restricted to this class itself
private Globals()
{
private Globals() {
observers = new ArrayList<>();
// Create a media session. NotificationCompat.MediaStyle
// PlayerService is your own Service or Activity responsible for media playback.
mediaSession = new MediaSessionCompat(App.getContext(), "Soniclair");
mediaSession.setCallback(new SonicLairSessionCallbacks());
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
stateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 1);
stateBuilder.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS);
stateBuilder.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS);
mediaSession.setPlaybackState(stateBuilder.build());
}

// Static method
// Static method to create instance of Singleton class
public static Globals getInstance()
{
public static Globals getInstance() {
if (single_instance == null)
single_instance = new Globals();

return single_instance;
}

public static void RegisterObserver(IBroadcastObserver observer){
public static void RegisterObserver(IBroadcastObserver observer) {
getInstance().observers.add(observer);
}

public static void UnregisterObserver(IBroadcastObserver observer){
public static void UnregisterObserver(IBroadcastObserver observer) {
getInstance().observers.remove(observer);
}

public static void NotifyObservers(String action, String value) {
if (Objects.equals(action, "EX")) {
Log.e("Soniclair Exception", value);
}
for (IBroadcastObserver observer : getInstance().observers) {
try{
try {
observer.update(action, value);
}
catch(Exception e){
} catch (Exception e) {
Log.e("SonicLair Globals", e.getMessage());
}
}
}

public static MediaSessionCompat GetMediaSession(){
public static MediaSessionCompat GetMediaSession() {
return getInstance().mediaSession;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,19 @@ class SubsonicClient(var initialAccount: Account) {
} else {
Log.i("BitmapMediaItem", "Loading from server")
val albumArtUri = Uri.parse(getAlbumArt(item.albumId))
val futureBitmap = Glide.with(App.context)
.asBitmap()
.load(albumArtUri)
.fallback(R.drawable.ic_album_art_fallback)
.error(R.drawable.ic_album_art_fallback)
.submit()
futureBitmap.get()
try {
val futureBitmap = Glide.with(App.context)
.asBitmap()
.load(albumArtUri)
.submit()
futureBitmap.get()
} catch (e: Exception) {
val placeholder = Glide.with(App.context)
.asBitmap()
.load(R.drawable.ic_album_art_fallback)
.submit()
placeholder.get()
}
}
Log.i("BitmapMediaItem", "Loaded successfully")
builder.setIconBitmap(albumArtBitmap)
Expand Down

1 comment on commit d9d2f9d

@vercel
Copy link

@vercel vercel bot commented on d9d2f9d Jul 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soniclair – ./

soniclair-thelinkin3000.vercel.app
soniclair-git-main-thelinkin3000.vercel.app
soniclair.vercel.app

Please sign in to comment.