private boolean isSearchResultPlayable() { boolean playable = false; if (searchResult.getSearchResult() instanceof StreamableSearchResult) { playable = ((StreamableSearchResult) searchResult.getSearchResult()).getStreamUrl() != null; if (searchResult.getExtension() != null) { MediaType mediaType = MediaType.getMediaTypeForExtension(searchResult.getExtension()); playable = mediaType != null && (mediaType.equals(MediaType.getAudioMediaType())) || mediaType.equals(MediaType.getVideoMediaType()); } } return playable; }
/** * Updates the Table based on the selection of the given table. Perform lookups to remove any * store files from the shared folder view and to only display store files in the store view */ void updateTableFiles(DirectoryHolder dirHolder) { if (dirHolder == null) { return; } if (dirHolder instanceof MediaTypeSavedFilesDirectoryHolder) { MediaType mediaType = ((MediaTypeSavedFilesDirectoryHolder) dirHolder).getMediaType(); setMediaType(mediaType); if (mediaType.equals(MediaType.getAudioMediaType())) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_AUDIO); } else if (mediaType == MediaType.getImageMediaType()) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_PICTURES); } else if (mediaType == MediaType.getDocumentMediaType()) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_DOCUMENTS); } else if (mediaType == MediaType.getVideoMediaType()) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_VIDEOS); } else if (mediaType == MediaType.getTorrentMediaType()) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_TORRENTS); } else if (mediaType == MediaType.getProgramMediaType()) { UXStats.instance().log(UXAction.LIBRARY_BROWSE_FILE_TYPE_APPLICATIONS); } } else { setMediaType(MediaType.getAnyTypeMediaType()); } clearTable(); List<List<File>> partitionedFiles = split(100, Arrays.asList(dirHolder.getFiles())); for (List<File> partition : partitionedFiles) { final List<File> fPartition = partition; BackgroundExecutorService.schedule( new Runnable() { @Override public void run() { for (final File file : fPartition) { GUIMediator.safeInvokeLater( new Runnable() { public void run() { addUnsorted(file); } }); } GUIMediator.safeInvokeLater( new Runnable() { public void run() { LibraryMediator.instance().getLibrarySearch().addResults(fPartition.size()); } }); } }); } forceResort(); }
private void uxLogMediaPreview() { MediaType mediaType = MediaType.getMediaTypeForExtension(searchResult.getExtension()); if (mediaType != null) { boolean isVideo = mediaType.equals(MediaType.getVideoMediaType()); UXStats.instance() .log( isVideo ? UXAction.SEARCH_RESULT_VIDEO_PREVIEW : UXAction.SEARCH_RESULT_AUDIO_PREVIEW); } }
public void scan(String filePath) { try { MediaType mt = MediaType.getMediaTypeForExtension(FilenameUtils.getExtension(filePath)); if (mt == null) { scanDocument(filePath, true); } else if (mt.equals(MediaType.getAudioMediaType())) { scanAudio(filePath, true); } else if (mt.equals(MediaType.getImageMediaType())) { scanPictures(filePath, true); } else if (mt.equals(MediaType.getVideoMediaType())) { scanVideo( filePath, true); // until we integrate mplayer for video and research metadata extraction } else { scanDocument(filePath, true); } } catch (Throwable e) { scanDocument(filePath, true); LOG.log(Level.WARNING, "Error scanning file, scanned as document: " + filePath, e); } }
/** 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); } }