/** Launches the associated applications for each selected file in the library if it can. */
  void launch(boolean playAudio) {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0) {
      return;
    }

    File selectedFile = DATA_MODEL.getFile(rows[0]);

    if (OSUtils.isWindows()) {
      if (selectedFile.isDirectory()) {
        GUIMediator.launchExplorer(selectedFile);
        return;
      } else if (!MediaPlayer.isPlayableFile(selectedFile)) {
        String extension = FilenameUtils.getExtension(selectedFile.getName());
        if (extension != null && extension.equals("torrent")) {
          GUIMediator.instance().openTorrentFile(selectedFile, true);
        } else {
          GUIMediator.launchFile(selectedFile);
        }
        return;
      }
    }

    LaunchableProvider[] providers = new LaunchableProvider[rows.length];
    boolean stopAudio = false;
    for (int i = 0; i < rows.length; i++) {
      try {
        MediaType mt =
            MediaType.getMediaTypeForExtension(
                FilenameUtils.getExtension(DATA_MODEL.getFile(rows[i]).getName()));
        if (mt.equals(MediaType.getVideoMediaType())) {
          stopAudio = true;
        }
      } catch (Throwable e) {
        // ignore
      }
      providers[i] = new FileProvider(DATA_MODEL.getFile(rows[i]));
    }
    if (stopAudio || !playAudio) {
      MediaPlayer.instance().stop();
    }

    if (playAudio) {
      GUILauncher.launch(providers);
      UXStats.instance()
          .log(stopAudio ? UXAction.LIBRARY_VIDEO_PLAY : UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE);
    } else {
      GUIMediator.launchFile(selectedFile);
    }
  }
    @Override
    public void actionPerformed(ActionEvent arg0) {
      File selectedFile = DATA_MODEL.getFile(TABLE.getSelectedRow());

      // can't create torrents out of empty folders.
      if (selectedFile.isDirectory() && selectedFile.listFiles().length == 0) {
        JOptionPane.showMessageDialog(
            null,
            I18n.tr("The folder you selected is empty."),
            I18n.tr("Invalid Folder"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      // can't create torrents if the folder/file can't be read
      if (!selectedFile.canRead()) {
        JOptionPane.showMessageDialog(
            null,
            I18n.tr("Error: You can't read on that file/folder."),
            I18n.tr("Error"),
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      CreateTorrentDialog dlg = new CreateTorrentDialog(GUIMediator.getAppFrame());
      dlg.setChosenContent(
          selectedFile,
          selectedFile.isFile() ? JFileChooser.FILES_ONLY : JFileChooser.DIRECTORIES_ONLY);
      dlg.setVisible(true);
    }
    public void actionPerformed(ActionEvent ae) {
      int[] sel = TABLE.getSelectedRows();
      if (sel.length == 0) {
        return;
      }

      File selectedFile = getFile(sel[0]);
      if (selectedFile.isFile() && selectedFile.getParentFile() != null) {
        GUIMediator.launchExplorer(selectedFile);
      }
    }
    private void updateDemuxingStatus(
        final File demuxed, final int totalDemuxed, final boolean demuxSuccess) {
      GUIMediator.safeInvokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              LibraryExplorer explorer = LibraryMediator.instance().getLibraryExplorer();
              explorer.enqueueRunnable(
                  new Runnable() {

                    @Override
                    public void run() {
                      if (demuxSuccess) {
                        add(demuxed, 0);
                        update(demuxed);
                        LibraryMediator.instance()
                            .getLibrarySearch()
                            .pushStatus(
                                I18n.tr("Finished")
                                    + " "
                                    + demuxedFiles.size()
                                    + " "
                                    + I18n.tr("out of")
                                    + " "
                                    + totalDemuxed
                                    + ". Extracting audio...");
                        System.out.println(
                            "Finished"
                                + demuxedFiles.size()
                                + " out of "
                                + totalDemuxed
                                + ". Extracting audio...");
                      } else {
                        LibraryMediator.instance()
                            .getLibrarySearch()
                            .pushStatus(
                                I18n.tr("Could not extract audio from") + " " + demuxed.getName());
                      }
                    }
                  });
              explorer.executePendingRunnables();
            }
          });
    }