/** Launches the associated applications for each selected file in the library if it can. */
  void launch(boolean playMedia) {
    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)) {
        GUIMediator.launchFile(selectedFile);
        return;
      }
    }

    LaunchableProvider[] providers = new LaunchableProvider[rows.length];
    for (int i = 0; i < rows.length; i++) {
      providers[i] = new FileProvider(DATA_MODEL.getFile(rows[i]));
    }
    if (!playMedia) {
      MediaPlayer.instance().stop();
    }

    if (playMedia) {
      GUILauncher.launch(providers);
    } else {
      GUIMediator.launchFile(selectedFile);
    }
  }
  /** 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);
    }
  }