Below is the main class of a project ive been working on, the goal is to start a countdown specified by the user. When the countdown reaches zero the base drops in the song that is being played. (Its not done yet) The main problem that arises is the fact that my song plays, and AFTER that, the timer starts.
Output:
Please input countdown in HH:mm:ss format.
00:00:41
Start?
Yes
The name of of the song is: Skrillex & Damian "Jr Gong" Marley - "Make It Bun Dem"
The time of base drop is: 00:00:41 //Song starts here
//Song is done
//Then timer starts
00:00:41
00:00:40
00:00:39
Thank you,
littlepresman
import java.util.ArrayList; import java.util.Scanner; public class AI { public static void main(String[] args) { System.out.println("Please input countdown in HH:mm:ss format."); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); songsBD playedSong = new songsBD(null, null, 0); String yes = "Yes"; System.out.println("Start?"); Scanner sc2 = new Scanner(System.in); String input2 = sc2.nextLine(); MP3 SkrillexDamian = new MP3("/home/luke/Desktop/CompSci/Music/MakeitBurnDem.mp3"); if (input2.contains(yes)) { playedSong = choose(convertTime(input)); System.out.println(playedSong); //Song starts here String sd = "Skrillex"; if(playedSong.get_name_of_song().contains(sd)) ///////////////////////////////////Plays the song ** { SkrillexDamian.play(); } countDown(convertTime(input)); ///////////////////////////////////////////////////////////Starts the timer ** } } public static double convertTime(String input) { String numbers[] = input.split(":"); String hr = numbers[0]; String min = numbers[1]; String sec = numbers[2]; int intHr = Integer.parseInt(hr); int intMin = Integer.parseInt(min); int intSec = Integer.parseInt(sec); int totalMin = intHr * 60 + intMin; int totalSec = totalMin * 60 + intSec; return totalSec; } public static void countDown(double sec) { for (double z = sec; z > 0; z--) { try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } String s = convertSec(z); System.out.println(s); } //Base drop starts here System.out.println("Base drop."); } public static String convertSec(double z) { int hours = (int) z / 3600; int minutes = (int) (z / 60) %60; int seconds = (int) z % 60; String res = hours + ":" + minutes + ":" + seconds; return res; } public static songsBD choose(double d) { ArrayList<songsBD> list = new ArrayList<songsBD>(); list.add(new songsBD("Skrillex & Damian \"Jr Gong\" Marley - \"Make It Bun Dem\"", "00:00:41", 41) ); for (int i = 0; i < list.size(); i++) { if (list.get(i).get_sec() == d) { return list.get(i); } } songsBD noSong = new songsBD("There is no song for this amount of time.", "00:00:00", 0); return noSong; } }