Search in sources :

Example 1 with MediaType

use of com.limegroup.gnutella.MediaType in project frostwire by frostwire.

the class LibraryFilesTableMediator method launch.

/**
 * Launches the associated applications for each selected file
 * in the library if it can.
 */
private 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.toLowerCase().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 != null && 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);
    }
}
Also used : MediaType(com.limegroup.gnutella.MediaType) File(java.io.File) LaunchableProvider(com.limegroup.gnutella.gui.util.GUILauncher.LaunchableProvider)

Example 2 with MediaType

use of com.limegroup.gnutella.MediaType in project frostwire by frostwire.

the class NativeFileIconController method preload.

/**
 * Preloads a bunch of icons.
 */
private void preload() {
    ExecutorService queue = ExecutorsHelper.newProcessingQueue("IconLoader");
    final MediaType[] types = MediaType.getDefaultMediaTypes();
    final AtomicBoolean continueLoading = new AtomicBoolean(true);
    for (int i = 0; i < types.length && continueLoading.get(); i++) {
        final Set<?> exts = types[i].getExtensions();
        for (Iterator<?> j = exts.iterator(); j.hasNext() && continueLoading.get(); ) {
            final String next = (String) j.next();
            queue.execute(new Runnable() {

                public void run() {
                    GUIMediator.safeInvokeAndWait(new Runnable() {

                        public void run() {
                            getIconForExtension(next);
                            if (!VIEW.isViewAvailable())
                                continueLoading.set(false);
                        }
                    });
                }
            });
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) MediaType(com.limegroup.gnutella.MediaType)

Example 3 with MediaType

use of com.limegroup.gnutella.MediaType in project frostwire by frostwire.

the class SearchResultActionsRenderer method isSearchResultPlayable.

private boolean isSearchResultPlayable() {
    boolean playable = false;
    if (searchResult.getSearchResult() instanceof StreamableSearchResult) {
        playable = ((StreamableSearchResult) searchResult.getSearchResult()).getStreamUrl() != null;
    }
    if (playable && searchResult.getExtension() != null) {
        MediaType mediaType = MediaType.getMediaTypeForExtension(searchResult.getExtension());
        playable = mediaType != null && (mediaType.equals(MediaType.getAudioMediaType())) || mediaType.equals(MediaType.getVideoMediaType());
    }
    return playable;
}
Also used : MediaType(com.limegroup.gnutella.MediaType) StreamableSearchResult(com.frostwire.search.StreamableSearchResult)

Example 4 with MediaType

use of com.limegroup.gnutella.MediaType in project frostwire by frostwire.

the class SearchResultActionsRenderer method uxLogMediaPreview.

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);
    }
}
Also used : MediaType(com.limegroup.gnutella.MediaType)

Example 5 with MediaType

use of com.limegroup.gnutella.MediaType in project frostwire by frostwire.

the class AbstractUISearchResult method play.

@Override
public void play() {
    // this gets invoked when clicking on a search result play preview button.
    if (sr instanceof StreamableSearchResult) {
        StreamableSearchResult ssr = (StreamableSearchResult) sr;
        String streamUrl = ssr.getStreamUrl();
        MediaType mediaType = MediaType.getMediaTypeForExtension(extension);
        if (mediaType != null) {
            boolean isVideo = mediaType.equals(MediaType.getVideoMediaType());
            if (isVideo) {
                boolean videoPreviewInBrowser = !PlayerSettings.USE_FW_PLAYER_FOR_CLOUD_VIDEO_PREVIEWS.getValue() && sr instanceof YouTubeCrawledStreamableSearchResult;
                if (videoPreviewInBrowser) {
                    GUIMediator.instance().launchYouTubePreviewInBrowser(((YouTubeCrawledStreamableSearchResult) sr));
                } else {
                    GUIMediator.instance().launchMedia(new StreamMediaSource(streamUrl, sr.getDisplayName(), sr.getDetailsUrl(), true), true);
                }
            } else {
                GUIMediator.instance().launchMedia(new StreamMediaSource(streamUrl, sr.getDisplayName(), sr.getDetailsUrl(), false), true);
            }
        }
    }
}
Also used : MediaType(com.limegroup.gnutella.MediaType) YouTubeCrawledStreamableSearchResult(com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult) StreamMediaSource(com.frostwire.gui.player.StreamMediaSource) StreamableSearchResult(com.frostwire.search.StreamableSearchResult) YouTubeCrawledStreamableSearchResult(com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult)

Aggregations

MediaType (com.limegroup.gnutella.MediaType)9 StreamableSearchResult (com.frostwire.search.StreamableSearchResult)2 File (java.io.File)2 StreamMediaSource (com.frostwire.gui.player.StreamMediaSource)1 YouTubeCrawledStreamableSearchResult (com.frostwire.search.youtube.YouTubeCrawledStreamableSearchResult)1 LaunchableProvider (com.limegroup.gnutella.gui.util.GUILauncher.LaunchableProvider)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1