Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class Main extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception{
- Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
- primaryStage.setTitle("Hello World");
- primaryStage.setScene(new Scene(root, 300, 275));
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- @Mod(modid = Radio.MOD_ID, name = Radio.MOD_NAME, version = Radio.MOD_VERSION)
- public class Radio {
- public static final String
- MOD_ID = "radio",
- MOD_NAME = "Radio",
- MOD_VERSION = "1.0";
- private final static KeyBinding playButton = new KeyBinding("key.playButton", Keyboard.KEY_NUMPAD5, "key.categories.radio");
- private final static KeyBinding stopButton = new KeyBinding("key.stopButton", Keyboard.KEY_NUMPAD4, "key.categories.radio");
- private MediaPlayerFX player;
- private static Logger logger;
- @Mod.EventHandler
- public void preInit(FMLPreInitializationEvent event) {
- logger = event.getModLog();
- if (event.getSide().isClient()) {
- ClientRegistry.registerKeyBinding(playButton);
- ClientRegistry.registerKeyBinding(stopButton);
- FMLCommonHandler.instance().bus().register(this);
- this.player = new MediaPlayerFX();
- }
- }
- @SubscribeEvent
- @SideOnly(Side.CLIENT)
- public void key(InputEvent.KeyInputEvent event) {
- if (playButton.isPressed()) {
- this.player.play();
- }
- if (stopButton.isPressed()) {
- this.player.stopped();
- }
- }
- private static class MediaPlayerFX extends Application {
- private MediaPlayer player;
- @Override
- public void start(Stage stage) throws Exception {
- this.player = new MediaPlayer(new Media("mp3 link"));
- this.player.setOnReady(() -> {
- logger.info("onReady");
- });
- this.player.setOnError(() -> {
- logger.info("onError");
- });
- this.player.setOnStopped(() -> {
- logger.info("onStopped");
- });
- this.player.setOnEndOfMedia(() -> {
- logger.info("onEndOfMedia");
- this.player.stop();
- });
- this.player.setOnPaused(() -> {
- logger.info("onPause");
- });
- }
- public static void main(String[] args) {
- launch(args);
- }
- private void play() {
- this.player.play();
- }
- private void stopped() {
- this.player.stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement