Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. public final class Main extends Application {
  2.  
  3. @Override
  4. public void start(Stage primaryStage) throws Exception{
  5. Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
  6. primaryStage.setTitle("Hello World");
  7. primaryStage.setScene(new Scene(root, 300, 275));
  8. primaryStage.show();
  9. }
  10.  
  11. public static void main(String[] args) {
  12. launch(args);
  13. }
  14.  
  15. }
  16.  
  17. @Mod(modid = Radio.MOD_ID, name = Radio.MOD_NAME, version = Radio.MOD_VERSION)
  18. public class Radio {
  19.  
  20. public static final String
  21. MOD_ID = "radio",
  22. MOD_NAME = "Radio",
  23. MOD_VERSION = "1.0";
  24.  
  25. private final static KeyBinding playButton = new KeyBinding("key.playButton", Keyboard.KEY_NUMPAD5, "key.categories.radio");
  26. private final static KeyBinding stopButton = new KeyBinding("key.stopButton", Keyboard.KEY_NUMPAD4, "key.categories.radio");
  27.  
  28. private MediaPlayerFX player;
  29. private static Logger logger;
  30.  
  31. @Mod.EventHandler
  32. public void preInit(FMLPreInitializationEvent event) {
  33.  
  34. logger = event.getModLog();
  35.  
  36. if (event.getSide().isClient()) {
  37. ClientRegistry.registerKeyBinding(playButton);
  38. ClientRegistry.registerKeyBinding(stopButton);
  39. FMLCommonHandler.instance().bus().register(this);
  40. this.player = new MediaPlayerFX();
  41. }
  42.  
  43. }
  44.  
  45. @SubscribeEvent
  46. @SideOnly(Side.CLIENT)
  47. public void key(InputEvent.KeyInputEvent event) {
  48.  
  49. if (playButton.isPressed()) {
  50. this.player.play();
  51. }
  52.  
  53. if (stopButton.isPressed()) {
  54. this.player.stopped();
  55. }
  56.  
  57. }
  58.  
  59. private static class MediaPlayerFX extends Application {
  60.  
  61. private MediaPlayer player;
  62.  
  63. @Override
  64. public void start(Stage stage) throws Exception {
  65. this.player = new MediaPlayer(new Media("mp3 link"));
  66.  
  67. this.player.setOnReady(() -> {
  68. logger.info("onReady");
  69. });
  70.  
  71. this.player.setOnError(() -> {
  72. logger.info("onError");
  73. });
  74.  
  75. this.player.setOnStopped(() -> {
  76. logger.info("onStopped");
  77. });
  78.  
  79. this.player.setOnEndOfMedia(() -> {
  80. logger.info("onEndOfMedia");
  81. this.player.stop();
  82. });
  83.  
  84. this.player.setOnPaused(() -> {
  85. logger.info("onPause");
  86. });
  87.  
  88. }
  89.  
  90. public static void main(String[] args) {
  91. launch(args);
  92. }
  93.  
  94. private void play() {
  95. this.player.play();
  96. }
  97.  
  98. private void stopped() {
  99. this.player.stop();
  100. }
  101.  
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement