diff --git a/pom.xml b/pom.xml index cea8df1..8d93cc6 100644 --- a/pom.xml +++ b/pom.xml @@ -136,4 +136,13 @@ https://jitpack.io + + + + github + mirkoebert + https://maven.pkg.github.com/mirkoebert/SimpleJavaRadioPlayerForSomaFM + + + diff --git a/src/main/java/com/mirkoebert/simplejavaradioplayer/Application.java b/src/main/java/com/mirkoebert/simplejavaradioplayer/Application.java index 7aa114a..3326a2f 100644 --- a/src/main/java/com/mirkoebert/simplejavaradioplayer/Application.java +++ b/src/main/java/com/mirkoebert/simplejavaradioplayer/Application.java @@ -1,5 +1,6 @@ package com.mirkoebert.simplejavaradioplayer; +import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +26,7 @@ public class Application extends JFrame { private final StationService stationService = new StationService(); private final String nameAndVersion; + private final StatusLine statusLine = new StatusLine(); @Autowired private PlayerService playerService; private JDialog donationBox; @@ -104,6 +106,8 @@ private void createLayout(final JComponent main, final JButton... buttons) { main.setPreferredSize(new Dimension(350, 400)); pane.add(lp, BorderLayout.CENTER); + pane.add(statusLine, BorderLayout.SOUTH); + val pane1 = new JOptionPane("Please support Soma FM and go to https://somafm.com/support/", INFORMATION_MESSAGE); donationBox = pane1.createDialog(pane, "Donate"); @@ -127,4 +131,8 @@ private void openSomaFmDonateLinkInDefaultBrowser() { } } + @PostConstruct + void registerObserver() { + playerService.addObserver(statusLine); + } } diff --git a/src/main/java/com/mirkoebert/simplejavaradioplayer/PlayerService.java b/src/main/java/com/mirkoebert/simplejavaradioplayer/PlayerService.java index bbdb8e0..65e7073 100644 --- a/src/main/java/com/mirkoebert/simplejavaradioplayer/PlayerService.java +++ b/src/main/java/com/mirkoebert/simplejavaradioplayer/PlayerService.java @@ -8,12 +8,13 @@ import org.springframework.stereotype.Service; import java.net.URL; +import java.util.Observable; import java.util.prefs.Preferences; @Service @RequiredArgsConstructor @Slf4j -public class PlayerService { +public class PlayerService extends Observable { private final ResilientStreamPlayer player; private final StationService stationService; @@ -26,10 +27,12 @@ void playButtonClicked() { switch (playerStatus) { case PLAYING -> { log.info("Stop"); + setStatus("Player stoped"); player.stop(); } case NOT_SPECIFIED, STOPPED -> { log.info("Start last station"); + setStatus("Player started with last station: " + stationService.getStationsNames()[stationService.getSelectedStationIndex()]); URL currenStationUrl = stationService.getSelectedStationPlsUrl(); log.info("Start station {}", currenStationUrl); final URL stream = playListService.getAudioStreamURL(currenStationUrl); @@ -41,6 +44,7 @@ void playButtonClicked() { void listItemSelected(int selectedIndex) { log.info("listItemSelected {}", selectedIndex); + setStatus("Play station: " + stationService.getStationsNames()[selectedIndex]); stationService.setSelectedStationIndex(selectedIndex); final URL nextStationUrl = stationService.getSelectedStationPlsUrl(); final Status playerStatus = player.getStatus(); @@ -56,7 +60,7 @@ void listItemSelected(int selectedIndex) { URL stream = playListService.getAudioStreamURL(nextStationUrl); player.playStream(stream); } - default -> log.warn("unsopprted operation for player status {}", playerStatus); + default -> log.warn("unsupported operation for player status {}", playerStatus); } } @@ -74,4 +78,9 @@ public void shutDown() { log.info("See You Space Cowboy"); player.stop(); } + + public void setStatus(String status) { + setChanged(); + notifyObservers(status); + } } diff --git a/src/main/java/com/mirkoebert/simplejavaradioplayer/StatusLine.java b/src/main/java/com/mirkoebert/simplejavaradioplayer/StatusLine.java new file mode 100644 index 0000000..66230b8 --- /dev/null +++ b/src/main/java/com/mirkoebert/simplejavaradioplayer/StatusLine.java @@ -0,0 +1,26 @@ +package com.mirkoebert.simplejavaradioplayer; + +import lombok.extern.slf4j.Slf4j; + +import javax.swing.*; +import java.util.Observable; +import java.util.Observer; + +@Slf4j +public class StatusLine extends JLabel implements Observer { + + + public StatusLine() { + super("Ready to play your favorite music.", SwingConstants.CENTER); + } + + @Override + public void update(Observable o, Object arg) { + log.info("Set status: {}", arg); + try { + setText((String) arg); + } catch (Exception e) { + log.warn("Can't set status {}", arg, e); + } + } +}