Last active
December 7, 2016 03:17
-
-
Save alejandrociatti/5841a6d4e1167386699bfbdc9f14ebf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import javafx.embed.swing.JFXPanel; | |
import javafx.scene.media.Media; | |
import javafx.scene.media.MediaPlayer; | |
// if we can access google, we can access everything (?) | |
fxPanel = new JFXPanel(); | |
file = new File("msg.mp3"); // of course you need a suitable audio file of your own | |
media = new Media(file.toURI().toString()); | |
mediaPlayer = new MediaPlayer(media); | |
tries = 0; | |
boolean isConnected(){ | |
try{ | |
println("["+tries+"]"+" looking for connection..."); | |
url = new URL("http://www.google.com.ar"); | |
connection = url.openConnection(); | |
connection.connect(); | |
return true; | |
} catch (Exception e){ | |
println("Something went wrong... looking for the interwebs..."); | |
sleep(5000); // 5s between attempts, reduce number if you're really impatient | |
return isConnected(); | |
} | |
} | |
if(isConnected()){ | |
mediaPlayer.play(); | |
println("we are connected!"); | |
System.exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment