Decoupled Player and PlayerGUI, dependency between the two is now injected instead.
This commit is contained in:
parent
e4e3ed6b6f
commit
95979fff29
5
pom.xml
5
pom.xml
@ -97,6 +97,11 @@
|
||||
<version>2.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>4.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
14
src/main/java/musicplayer/BindingsModule.java
Normal file
14
src/main/java/musicplayer/BindingsModule.java
Normal file
@ -0,0 +1,14 @@
|
||||
package musicplayer;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.player.IPlayer;
|
||||
import musicplayer.player.GStreamerPlayer;
|
||||
|
||||
public class BindingsModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(IPlayer.class).to(GStreamerPlayer.class);
|
||||
bind(PlayerCallbackInterface.class).to(PlayerGUI.class);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package musicplayer;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import musicplayer.callbacks.LibraryCallbackInterface;
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.db.DatabaseManager;
|
||||
@ -8,6 +11,7 @@ import musicplayer.model.Album;
|
||||
import musicplayer.model.Artist;
|
||||
import musicplayer.model.HasSongs;
|
||||
import musicplayer.model.Song;
|
||||
import musicplayer.player.IPlayer;
|
||||
import musicplayer.swingmodels.PlaylistTableModel;
|
||||
import musicplayer.util.Icons;
|
||||
import musicplayer.util.LibraryUtils;
|
||||
@ -47,7 +51,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
private final JTable playList = new JTable();
|
||||
private JSlider seekBar;
|
||||
private final JComboBox<String> libraryDisplayType = new JComboBox<>();
|
||||
private final Player player = new Player(this);
|
||||
private final IPlayer player;
|
||||
private final PlaylistTableModel playlistTableModel = new PlaylistTableModel(new ArrayList<>());
|
||||
private static final DefaultMutableTreeNode updatingNode = new DefaultMutableTreeNode();
|
||||
private boolean libraryUpdating = false;
|
||||
@ -55,7 +59,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
private final Map<String, Runnable> libraryDisplayVariants = createDisplayVariantMap();
|
||||
|
||||
public PlayerGUI() {
|
||||
@Inject
|
||||
public PlayerGUI(IPlayer player) {
|
||||
this.player = player;
|
||||
createUI();
|
||||
resetTree();
|
||||
Thread seekBarUpdater = new Thread(() -> {
|
||||
@ -97,7 +103,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
public static void main(String[] args) {
|
||||
DatabaseManager.init();
|
||||
PlayerGUI playerGUI = new PlayerGUI();
|
||||
Injector injector = Guice.createInjector(new BindingsModule());
|
||||
PlayerGUI playerGUI = injector.getInstance(PlayerGUI.class);
|
||||
JFrame frame = new JFrame();
|
||||
frame.setMinimumSize(new Dimension(600, 400));
|
||||
frame.setContentPane(playerGUI.mainPanel);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package musicplayer;
|
||||
package musicplayer.player;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import musicplayer.StartPlayingException;
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.model.Song;
|
||||
import org.gstreamer.ClockTime;
|
||||
@ -11,7 +13,7 @@ import org.gstreamer.elements.PlayBin2;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
class Player {
|
||||
public class GStreamerPlayer implements IPlayer{
|
||||
|
||||
private final PlayBin2 playBin;
|
||||
|
||||
@ -25,7 +27,8 @@ class Player {
|
||||
* Manages GStreamer based playback operations.
|
||||
* @param callbackInterface Interface on which UI updates can be called.
|
||||
*/
|
||||
public Player(PlayerCallbackInterface callbackInterface) {
|
||||
@Inject
|
||||
public GStreamerPlayer(PlayerCallbackInterface callbackInterface) {
|
||||
this.callbackInterface = callbackInterface;
|
||||
Gst.init();
|
||||
playBin = new PlayBin2("BusMessages");
|
19
src/main/java/musicplayer/player/IPlayer.java
Normal file
19
src/main/java/musicplayer/player/IPlayer.java
Normal file
@ -0,0 +1,19 @@
|
||||
package musicplayer.player;
|
||||
|
||||
import musicplayer.StartPlayingException;
|
||||
import musicplayer.model.Song;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IPlayer {
|
||||
void playSong(Optional<Song> inputSong) throws StartPlayingException;
|
||||
void stop();
|
||||
void resume();
|
||||
void pause();
|
||||
Song getCurrentSong();
|
||||
int currentSongPosition();
|
||||
void setVolume(int volume);
|
||||
int getVolume();
|
||||
void seek(int position);
|
||||
boolean isPlaying();
|
||||
}
|
Loading…
Reference in New Issue
Block a user