From 82124265f1e56d9992d7fdeb1380b8b0d2a0fa4b Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 19:56:23 +0100 Subject: [PATCH] Play functions code added --- src/main/java/device/usbPlayer/UsbPlayer.java | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index ad187e8..65a2be0 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -57,15 +57,35 @@ public class UsbPlayer implements Device { return Lautstaerke; } - @Override - public void louder() { - if(Lautstaerke < 100) { - Lautstaerke += 1; - } else { - Lautstaerke = 100; + //*********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; } - //*********setters und getters******** + //**********search method************* @Override public void quieter() { if(Lautstaerke > 0) { @@ -75,6 +95,15 @@ public class UsbPlayer implements Device { } } + @Override + public void louder() { + if(Lautstaerke < 100) { + Lautstaerke += 1; + } else { + Lautstaerke = 100; + } + } + @Override public int getVolume() { return 0; @@ -108,7 +137,29 @@ public class UsbPlayer implements Device { @Override public String play() { - return null; + 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; + } }