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.
172 lines
4.0 KiB
172 lines
4.0 KiB
package device.usbPlayer;
|
|
|
|
import device.Device;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class UsbPlayer implements Device {
|
|
|
|
private ArrayList<String> Playlist = new ArrayList<String>();
|
|
private String playTrack = "";
|
|
private Boolean isConnected;
|
|
private Boolean isDefect;
|
|
int Lautstaerke = 0;
|
|
|
|
//*********setters und getters********
|
|
public ArrayList<String> getPlaylist() {
|
|
return Playlist;
|
|
}
|
|
|
|
public void setPlaylist(ArrayList<String> playlist) {
|
|
Playlist = playlist;
|
|
}
|
|
|
|
public Boolean getDefect() {
|
|
return isDefect;
|
|
}
|
|
|
|
public void setDefect(Boolean defect) {
|
|
isDefect = defect;
|
|
}
|
|
|
|
|
|
public Boolean getConnected() {
|
|
return isConnected;
|
|
}
|
|
|
|
public void setConnected(Boolean connected) {
|
|
isConnected = connected;
|
|
}
|
|
|
|
public String getPlayTrack() {
|
|
return playTrack;
|
|
}
|
|
|
|
public void setPlayTrack(String playTrack) {
|
|
this.playTrack = playTrack;
|
|
}
|
|
|
|
|
|
public void setLautstaerke(int ls) {
|
|
if (ls <= 100) {
|
|
Lautstaerke = ls;
|
|
}
|
|
}
|
|
|
|
public int getLautstaerke() {
|
|
return Lautstaerke;
|
|
}
|
|
|
|
//*********constructure********
|
|
public UsbPlayer() {
|
|
super();
|
|
isDefect = false;
|
|
isConnected = true;
|
|
Playlist.add("Musik 01.mp3");
|
|
Playlist.add("Musik 02.mp3");
|
|
Playlist.add("Musik 03.mp3");
|
|
playTrack = Playlist.get(0);
|
|
|
|
}
|
|
//**********search method*************
|
|
private boolean isAllAudio() {
|
|
|
|
String song = "";
|
|
boolean flag = true;
|
|
|
|
for (int i = 0; i < Playlist.size(); i++) {
|
|
song = Playlist.get(i).substring(Playlist.get(i).length() - 4);
|
|
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".wav")) {
|
|
flag = true;
|
|
} else {
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
//**********search method*************
|
|
@Override
|
|
public void quieter() {
|
|
if(Lautstaerke > 0) {
|
|
Lautstaerke -= 1;
|
|
} else {
|
|
Lautstaerke = 0;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void louder() {
|
|
if(Lautstaerke < 100) {
|
|
Lautstaerke += 1;
|
|
} else {
|
|
Lautstaerke = 100;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getVolume() {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public void next() {
|
|
int currentIdex = Playlist.indexOf(playTrack);
|
|
int nextIndex = (currentIdex + 1) % Playlist.size();
|
|
playTrack = Playlist.get(nextIndex);
|
|
}
|
|
|
|
@Override
|
|
public void prev() {
|
|
int currentIdex = Playlist.indexOf(playTrack);
|
|
int nextIndex = Playlist.size() - 1;
|
|
if (currentIdex != 0) {
|
|
nextIndex = (currentIdex - 1);
|
|
}
|
|
playTrack = Playlist.get(nextIndex);
|
|
}
|
|
|
|
@Override
|
|
public String getInfoText() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public String[] getOptions() {
|
|
return new String[0];
|
|
}
|
|
|
|
@Override
|
|
public String[] getItemList() {
|
|
return new String[0];
|
|
}
|
|
|
|
|
|
@Override
|
|
public String play() {
|
|
String result = "USB : ";
|
|
if (isConnected == true) {
|
|
result += "connected,";
|
|
if (isDefect == false) {
|
|
result += "working";
|
|
if (this.Playlist.size() != 0) {
|
|
result += ",have a list";
|
|
if (this.isAllAudio()) {
|
|
result += ",Audio";
|
|
if (!playTrack.equals(""))
|
|
result += ",point to a track.";
|
|
else
|
|
result += ",doesn't point to a track.";
|
|
} else {
|
|
result += ",not Audio.";
|
|
}
|
|
} else result += ",have no list.";
|
|
} else {
|
|
result += "not working.";
|
|
}
|
|
} else result = "not connected.";
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|