You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
274 lines
10 KiB
274 lines
10 KiB
package device.radioPlayer;
|
|
|
|
import device.Device;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
|
|
public class RadioPlayer implements Device {
|
|
|
|
private int x;
|
|
|
|
public RadioPlayer() {
|
|
super();
|
|
savedPlaylist.add("YouFM");
|
|
savedPlaylist.add("Teddy");
|
|
savedPlaylist.add("MegaHits");
|
|
playedStation = savedPlaylist.get(0);
|
|
}
|
|
|
|
ArrayList<String> savedPlaylist = new ArrayList<String>();
|
|
ArrayList<String> regionPlaylist = new ArrayList<String>();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
int hour = now.getHour();
|
|
int Lautstaerke = 0;
|
|
int savedVolume;
|
|
String playedStation = "";
|
|
|
|
public String getYouFMInfoByTime(int x) {
|
|
if (x >= 5 && x < 10) return YouFMInfo[0];
|
|
else if (x >= 10 && x < 14) return YouFMInfo[1];
|
|
else if (x >= 14 && x < 18) return YouFMInfo[2];
|
|
else if (x >= 18 && x < 20) return YouFMInfo[3];
|
|
else if (x >= 20 && x < 22) return YouFMInfo[4];
|
|
else if (x >= 22 && x <= 23) return YouFMInfo[5];
|
|
else return YouFMInfo[6];
|
|
}
|
|
|
|
String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"};
|
|
|
|
public String getBR3InfoByTime(int x) {
|
|
if (x >= 5 && x < 9) return BR3Info[0];
|
|
else if (x >= 9 && x < 12) return BR3Info[1];
|
|
else if (x == 12) return BR3Info[2];
|
|
else if (x >= 13 && x < 16) return BR3Info[3];
|
|
else if (x >= 16 && x < 19) return BR3Info[4];
|
|
else if (x >= 19 && x < 21) return BR3Info[5];
|
|
else if (x >= 21 && x < 24) return BR3Info[6];
|
|
else return BR3Info[7];
|
|
}
|
|
|
|
String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"};
|
|
|
|
public String getAntenneBYInfoByTime(int x) {
|
|
if (x >= 5 && x < 9) return AntenneBYInfo[0];
|
|
else if (x >= 9 && x < 12) return AntenneBYInfo[1];
|
|
else if (x >= 12 && x < 15) return AntenneBYInfo[2];
|
|
else if (x >= 15 && x < 19) return AntenneBYInfo[3];
|
|
else return AntenneBYInfo[4];
|
|
}
|
|
|
|
String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
|
|
|
|
|
|
public void setLautstaerke(int lautstaerke) {
|
|
Lautstaerke = lautstaerke;
|
|
}
|
|
|
|
public void changeRegion(String region) {
|
|
switch (region) {
|
|
case "BY":
|
|
regionPlaylist.clear();
|
|
regionPlaylist.add("Antenne Bayern");
|
|
regionPlaylist.add("Bayern 1");
|
|
regionPlaylist.add("Bayern 3");
|
|
regionPlaylist.add("Hit Radio N1");
|
|
playedStation = regionPlaylist.get(0);
|
|
break;
|
|
case "HE":
|
|
regionPlaylist.clear();
|
|
regionPlaylist.add("Hit Radio FFH");
|
|
regionPlaylist.add("HR 1");
|
|
regionPlaylist.add("HR 3");
|
|
regionPlaylist.add("YouFM");
|
|
playedStation = regionPlaylist.get(0);
|
|
break;
|
|
case "BW":
|
|
regionPlaylist.clear();
|
|
regionPlaylist.add("DASDING");
|
|
regionPlaylist.add("SWR 1");
|
|
regionPlaylist.add("SWR 3");
|
|
regionPlaylist.add("sunshine live");
|
|
playedStation = regionPlaylist.get(0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void louder() {
|
|
if (Lautstaerke < 100) {
|
|
Lautstaerke += 1;
|
|
} else Lautstaerke = 100;
|
|
}
|
|
|
|
@Override
|
|
public void quieter() {
|
|
if (Lautstaerke > 0) {
|
|
Lautstaerke -= 1;
|
|
} else Lautstaerke = 0;
|
|
}
|
|
|
|
@Override
|
|
public int getVolume() {
|
|
return Lautstaerke;
|
|
}
|
|
|
|
@Override
|
|
public void next() {
|
|
if (regionPlaylist.contains(playedStation)) {
|
|
int currentIndex = regionPlaylist.indexOf(playedStation);
|
|
int nextIndex = (currentIndex + 1) % regionPlaylist.size();
|
|
playedStation = regionPlaylist.get(nextIndex);
|
|
} else {
|
|
int currentIndex = savedPlaylist.indexOf(playedStation);
|
|
int nextIndex = (currentIndex + 1) % savedPlaylist.size();
|
|
playedStation = savedPlaylist.get(nextIndex);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void prev() {
|
|
if (regionPlaylist.contains(playedStation)) {
|
|
int currentIndex = regionPlaylist.indexOf(playedStation);
|
|
int nextIndex = regionPlaylist.size() - 1;
|
|
if (currentIndex != 0) {
|
|
nextIndex = (currentIndex - 1);
|
|
}
|
|
playedStation = regionPlaylist.get(nextIndex);
|
|
} else {
|
|
{
|
|
int currentIndex = savedPlaylist.indexOf(playedStation);
|
|
int nextIndex = savedPlaylist.size() - 1;
|
|
if (currentIndex != 0) {
|
|
nextIndex = (currentIndex - 1);
|
|
}
|
|
playedStation = savedPlaylist.get(nextIndex);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getInfoText() {
|
|
return "InfoText";
|
|
}
|
|
|
|
@Override
|
|
public String[] getOptions() {
|
|
return new String[0];
|
|
}
|
|
|
|
@Override
|
|
public String chooseItem(int itemNr) {
|
|
if (regionPlaylist.contains(playedStation)) {
|
|
if (itemNr > regionPlaylist.size()) {
|
|
playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
|
|
return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
|
|
} else if (itemNr < 1) {
|
|
playedStation = regionPlaylist.get(0);
|
|
return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
|
|
} else {
|
|
playedStation = regionPlaylist.get(itemNr - 1);
|
|
return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
|
|
}
|
|
} else {
|
|
if (itemNr > savedPlaylist.size()) {
|
|
playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
|
|
return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
|
|
} else if (itemNr < 1) {
|
|
playedStation = savedPlaylist.get(0);
|
|
return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
|
|
} else {
|
|
playedStation = savedPlaylist.get(itemNr - 1);
|
|
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String[] getItemList() {
|
|
if (regionPlaylist.contains(playedStation))
|
|
return regionPlaylist.toArray(new String[0]);
|
|
else
|
|
return savedPlaylist.toArray(new String[0]);
|
|
}
|
|
|
|
@Override
|
|
public String mute() {
|
|
savedVolume = getVolume();
|
|
setLautstaerke(0);
|
|
return "RadioPlayer is muted now";
|
|
}
|
|
|
|
@Override
|
|
public String unmute() {
|
|
setLautstaerke(savedVolume);
|
|
return ("RadioPlayer is unmuted Volume is set to " + getVolume());
|
|
}
|
|
|
|
|
|
@Override
|
|
public String play() {
|
|
if (regionPlaylist.contains(playedStation))
|
|
return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
|
|
else
|
|
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
|
|
}
|
|
|
|
public String showStationInfo() {
|
|
switch (playedStation) {
|
|
case "Antenne Bayern":
|
|
return getAntenneBYInfoByTime(hour);
|
|
case "YouFM":
|
|
return getYouFMInfoByTime(hour);
|
|
case "Bayern 3":
|
|
return getBR3InfoByTime(hour);
|
|
default:
|
|
return "";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public String saveStation() {
|
|
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
|
|
else savedPlaylist.add(playedStation);
|
|
regionPlaylist.clear();
|
|
return "Station " + playedStation + " is saved in your Station list";
|
|
}
|
|
|
|
|
|
public String deleteStation() {
|
|
String station = playedStation;
|
|
if ((savedPlaylist.size()) > 1) {
|
|
savedPlaylist.remove(playedStation);
|
|
playedStation = savedPlaylist.get(0);
|
|
return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
|
|
} else return " Last Station: 01 " + station + " can´t by deleted";
|
|
}
|
|
|
|
public String changeToSavedPlaylist() {
|
|
if (regionPlaylist.contains(playedStation)) {
|
|
playedStation = savedPlaylist.get(0);
|
|
regionPlaylist.clear();
|
|
return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
|
|
}
|
|
return "You are already in saved Playlist!";
|
|
}
|
|
|
|
public String changeOrderInSavedPlaylist(int nr) {
|
|
String station = playedStation;
|
|
if ((nr - 1) > savedPlaylist.size()) {
|
|
savedPlaylist.remove(playedStation);
|
|
savedPlaylist.add(savedPlaylist.size(), station);
|
|
return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
|
|
} else if (nr < 0) {
|
|
savedPlaylist.remove(playedStation);
|
|
savedPlaylist.add(0, station);
|
|
return "Station " + playedStation + " is now on place 01 in saved playlist";
|
|
} else {
|
|
savedPlaylist.remove(playedStation);
|
|
savedPlaylist.add(nr - 1, station);
|
|
return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
|
|
}
|
|
}
|
|
}
|