Ejemplo n.º 1
0
 private void generateDone() throws IOException {
   wait.setVisible(false);
   wait.dispose();
   Player.activeMenubar();
   JOptionPane.showMessageDialog(
       contentPane,
       "The video has been geneated successfully!",
       null,
       JOptionPane.INFORMATION_MESSAGE);
   Player.playVideo(mergedVideo);
 }
  public Packet handleMessage(int clientId) {
    String name = messagePacket.getName();
    String message = messagePacket.getMessage();
    String playerPrefix = messagePacket.getPlayerPrefix();
    boolean playerIsMod = messagePacket.isPlayerIsMod();

    Player player = PlayerHandler.INSTANCE.getPlayerFromPlayerName(name);

    if (player == null) {
      PlayerHandler.INSTANCE.playerLogin(name, clientId);
    }
    player = PlayerHandler.INSTANCE.getPlayerFromPlayerName(name);

    // check to see if player is currently in a pm;

    Channel channel = ChannelHandler.INSTANCE.getChannelFromChannelName(player.getActiveChannel());

    if (player.isMuted()) {
      return new PlayerMessage(name, "You are muted");
    } else {
      channel.SendMessage(message, playerPrefix, name, playerIsMod);
    }
    return null;
  }
Ejemplo n.º 3
0
  // A pop-up window for "Merge video and audio, generate new file" feature
  public AddAudio() {
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(200, 200, 450, 150);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout());

    save = new JFileChooser();
    defaultPath = new File(Player.currentDir + "/video.mp4");
    save.setSelectedFile(defaultPath);

    JPanel butPanel = new JPanel();
    JButton btnOverlay = new JButton("Overlay");
    JButton btnOverlap = new JButton("Overlap");
    JButton cancel = new JButton("Cancel");

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            Player.activeMenubar();
            dispose();
          }
        });

    // Cancel button, close the window
    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Player.activeMenubar();
            dispose();
          }
        });

    // Merge the video and audio file without deleting origin audio of video
    btnOverlap.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            if (videoPath.getText().length() == 0 || mp3Path.getText().length() == 0) {
              JOptionPane.showMessageDialog(
                  contentPane, "File Path Can Not Be Empty!", null, JOptionPane.WARNING_MESSAGE);

            } else {
              if (videoFile.exists() && audioFile.exists()) {
                Player.disableMenubar();
                String videoPath = videoFile.getAbsolutePath();
                System.out.println(videoPath);
                String audioPath = audioFile.getAbsolutePath();
                System.out.println(audioPath);
                int returnVal = save.showSaveDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                  wait = new Message_Wait();
                  String path = save.getSelectedFile().getPath();
                  System.out.println(path);
                  VideoProcesser vp =
                      new VideoProcesser(
                          "ffmpeg -y -i "
                              + videoPath
                              + " -i "
                              + audioPath
                              + " -map 0:v -map 1:a "
                              + path);
                  vp.execute();
                  setVisible(false);
                  mergedVideo = new File(path);
                }
              }
            }
          }
        });

    // Merge the video and audio file with origin audio of video deleted
    btnOverlay.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {

            if (videoPath.getText().length() == 0 || mp3Path.getText().length() == 0) {
              JOptionPane.showMessageDialog(
                  contentPane, "File Path Can Not Be Empty!", null, JOptionPane.WARNING_MESSAGE);

            } else {
              if (videoFile.exists() && audioFile.exists()) {
                Player.disableMenubar();
                String videoPath = videoFile.getAbsolutePath();
                System.out.println(videoPath);
                String audioPath = audioFile.getAbsolutePath();
                System.out.println(audioPath);

                int returnVal = save.showSaveDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                  String path = save.getSelectedFile().getPath();
                  wait = new Message_Wait();
                  VideoProcesser vp =
                      new VideoProcesser(
                          "ffmpeg -y -i "
                              + videoPath
                              + " -i "
                              + audioPath
                              + " -filter_complex amix=inputs=2 "
                              + path);
                  vp.execute();
                  setVisible(false);
                  mergedVideo = new File(path);
                }
              }
            }
          }
        });

    butPanel.add(btnOverlay);
    butPanel.add(btnOverlap);
    butPanel.add(cancel, BorderLayout.AFTER_LAST_LINE);
    contentPane.add(butPanel, BorderLayout.SOUTH);

    // Choose the video file
    JPanel videoPanel = new JPanel();
    JButton change = new JButton("Change");

    videoPath = new JTextField();
    JLabel vpath = new JLabel(" Video Path:    ");
    if (Player.getMediaPath().length() != 0) {
      videoPath.setText(Player.getMediaPath() + "");
      videoFile = Player.getVideoFile();
    }

    videoPath.setPreferredSize(new Dimension(200, 20));
    videoPanel.add(vpath);
    videoPanel.add(videoPath);
    videoPanel.add(change);
    change.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            videoFile =
                FileOperation.chooseFile(
                    Player.fileSelector,
                    new FileNameExtensionFilter("Video File", "avi", "mp4"),
                    JFileChooser.FILES_ONLY,
                    "video file");
            videoPath.setText(videoFile.getAbsolutePath());
          }
        });

    // Choose the MP3 audio file
    JButton change1 = new JButton("Change");
    JLabel mpath = new JLabel("MP3 File Path: ");
    mp3Path = new JTextField();
    mp3Path.setPreferredSize(new Dimension(200, 20));
    JPanel mp3Panel = new JPanel();
    mp3Panel.add(mpath);
    mp3Panel.add(mp3Path);
    mp3Panel.add(change1);
    change1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            audioFile =
                FileOperation.chooseFile(
                    Player.fileSelector,
                    new FileNameExtensionFilter("MP3", "mp3"),
                    JFileChooser.FILES_ONLY,
                    "audio file");
            mp3Path.setText(audioFile.getAbsolutePath());
          }
        });

    contentPane.add(mp3Panel, BorderLayout.CENTER);
    contentPane.add(videoPanel, BorderLayout.NORTH);

    setContentPane(contentPane);
    setVisible(true);
  }
 /**
  * The following method creates a State with the given parameters and adds that instance of the
  * State class into the memory. Takes in an instance of the Model class which represents the model
  * of the program and an instance of the SquareSpace that is the previous space that the player
  * was on.
  *
  * @param Player player - an instance of the Player class
  * @param SquareSpace space - an instance of the SquareSpace class
  */
 public void createState(Player player, SquareSpace space) {
   int score = space.getValue() - player.getSpace().getValue();
   State state = new State(score, player, player.getSpace(), space);
   memory.add(state);
 }