Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
tryfix some stupid bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vhaudiquet committed Dec 23, 2018
1 parent 4fac822 commit 0acb30d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
13 changes: 8 additions & 5 deletions app/src/main/java/v/blade/player/PlayerMediaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,15 @@ public void playSong(final Song song)
if(song == null) return;
currentSong = song;

if(currentActivePlayer != null) currentActivePlayer.pause(null); //even if player if not playing, we pause (in case player was about to play)

/* select appropriate mediaplayer and start playback */
if(song.getSources().getSourceByPriority(0) == null)
{currentState = PLAYER_STATE_PAUSED; listener.onStateChange();}
currentActivePlayer = song.getSources().getSourceByPriority(0).getSource().getPlayer();
//check if the song is available
if(song.getSources().getSourceByPriority(0) == null) {currentState = PLAYER_STATE_PAUSED; listener.onStateChange();}

//switch mediaplayers
//if the mediaplayer is the same, we need to use little tricks to prevent a brutal transition
SourcePlayer nextPlayer = song.getSources().getSourceByPriority(0).getSource().getPlayer();
if(currentActivePlayer != null && currentActivePlayer != nextPlayer) currentActivePlayer.pause(null); //even if player if not playing, we pause (in case player was about to play)
currentActivePlayer = nextPlayer;

if(requestAudioFocus())
{
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/v/blade/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,19 @@ public void onGlobalLayout()
navigationView.setItemBackgroundResource(ThemesActivity.currentColorBackground);
navigationView.setBackgroundColor(ContextCompat.getColor(this, ThemesActivity.currentColorBackground));
navigationView.getHeaderView(0).setBackgroundColor(ContextCompat.getColor(this, ThemesActivity.currentColorPrimary));

PlayerConnection.init(connectionCallbacks, getApplicationContext());
LibraryService.configureLibrary(getApplicationContext());
checkPermission();
}

/*
@Override
protected void onStart()
{
super.onStart();
PlayerConnection.init(connectionCallbacks, getApplicationContext());
LibraryService.configureLibrary(getApplicationContext());
checkPermission();
}
*/

@Override
protected void onDestroy()
Expand Down Expand Up @@ -826,16 +829,22 @@ private void setPlaylist(ArrayList<Song> songs, int currentPos)
return;
}

if(!PlayerConnection.isServiceStarted) PlayerConnection.start();

if(musicPlayer == null) System.err.println("MusicPlayer is NULL ! Where is PlayerService??");
else musicPlayer.setCurrentPlaylist(songs, currentPos);
}
private void playNext(ArrayList<Song> songs)
{
if(!PlayerConnection.isServiceStarted) PlayerConnection.start();

if(musicPlayer == null) System.err.println("MusicPlayer is NULL ! Where is PlayerService??");
else musicPlayer.addNextToPlaylist(songs);
}
private void addToPlaylist(ArrayList<Song> songs)
{
if(!PlayerConnection.isServiceStarted) PlayerConnection.start();

if(musicPlayer == null) System.err.println("MusicPlayer is NULL ! Where is PlayerService??");
else musicPlayer.addToPlaylist(songs);
}
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/v/blade/ui/PlayerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;
import android.support.v4.media.session.MediaControllerCompat;
import v.blade.library.Song;
Expand All @@ -38,6 +39,7 @@ public class PlayerConnection
private static ArrayList<Song> playOnConnect; private static int positionOnConnect;
private static volatile PlayerService musicPlayer = null;
public static MediaControllerCompat musicController;
public static boolean isServiceStarted = false;
private static ServiceConnection musicConnection = new ServiceConnection()
{
@Override
Expand Down Expand Up @@ -76,19 +78,14 @@ public static boolean init(Callback connectionCallback, Context applicationConte
return applicationContext.bindService(serv, musicConnection, Context.BIND_AUTO_CREATE);
}

/*
public static void start(ArrayList<Song> songs, int currentPos)
public static void start()
{
playOnConnect = songs;
positionOnConnect = currentPos;
Intent serv = new Intent(applicationContext, PlayerService.class);
if(Build.VERSION.SDK_INT >= 26) applicationContext.startForegroundService(serv);
else applicationContext.startService(serv);

applicationContext.bindService(serv, musicConnection, Context.BIND_ABOVE_CLIENT);
}*/
isServiceStarted = true;
}

public static PlayerService getService()
{
Expand Down

0 comments on commit 0acb30d

Please sign in to comment.