Search in sources :

Example 1 with MediaSource

use of com.frostwire.gui.player.MediaSource in project frostwire by frostwire.

the class LibraryActionsRenderer method onPlayAction.

@Override
protected void onPlayAction() {
    if (actionsHolder != null && actionsHolder.getDataLine() != null) {
        MediaSource mediaSource = null;
        List<MediaSource> filesView = null;
        Object dataLine = actionsHolder.getDataLine();
        if (dataLine instanceof LibraryFilesTableDataLine) {
            mediaSource = new MediaSource(((LibraryFilesTableDataLine) dataLine).getFile());
            filesView = LibraryFilesTableMediator.instance().getFilesView();
        } else if (dataLine instanceof LibraryPlaylistsTableDataLine) {
            mediaSource = new MediaSource(((LibraryPlaylistsTableDataLine) dataLine).getPlayListItem());
            filesView = LibraryPlaylistsTableMediator.instance().getFilesView();
        }
        if (mediaSource != null && !actionsHolder.isPlaying()) {
            MediaPlayer.instance().asyncLoadMedia(mediaSource, true, null, filesView);
        }
    }
}
Also used : MediaSource(com.frostwire.gui.player.MediaSource)

Example 2 with MediaSource

use of com.frostwire.gui.player.MediaSource in project frostwire by frostwire.

the class LibraryFilesTableMediator method handleActionKey.

public void handleActionKey() {
    LibraryFilesTableDataLine line = DATA_MODEL.get(TABLE.getSelectedRow());
    if (line == null || line.getFile() == null) {
        return;
    }
    if (getMediaType().equals(MediaType.getAudioMediaType()) && MediaPlayer.isPlayableFile(line.getFile())) {
        MediaPlayer.instance().asyncLoadMedia(new MediaSource(line.getFile()), true, null, getFilesView());
        UXStats.instance().log(UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE);
        return;
    }
    launch(true);
}
Also used : MediaSource(com.frostwire.gui.player.MediaSource)

Example 3 with MediaSource

use of com.frostwire.gui.player.MediaSource in project frostwire by frostwire.

the class TransferActionsRenderer method onPlay.

private void onPlay() {
    if (dl.canPreview() && !isDlBeingPlayed()) {
        File file = dl.getPreviewFile();
        if (file != null) {
            GUIMediator.instance().launchMedia(new MediaSource(file), !dl.isCompleted());
        }
        updatePlayButton();
    }
}
Also used : MediaSource(com.frostwire.gui.player.MediaSource) File(java.io.File)

Example 4 with MediaSource

use of com.frostwire.gui.player.MediaSource in project frostwire by frostwire.

the class LibraryPlaylistsTableMediator method getFilesView.

@Override
public List<MediaSource> getFilesView() {
    int size = DATA_MODEL.getRowCount();
    List<MediaSource> result = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        try {
            result.add(new MediaSource(DATA_MODEL.get(i).getPlayListItem()));
        } catch (Exception e) {
            return Collections.emptyList();
        }
    }
    return result;
}
Also used : MediaSource(com.frostwire.gui.player.MediaSource) ArrayList(java.util.ArrayList)

Example 5 with MediaSource

use of com.frostwire.gui.player.MediaSource in project frostwire by frostwire.

the class GUIUtils method launchFile.

/**
 * Internal launch of a song to play.
 * @param file - song to play
 * @param playOneTime - if true, begin playing song immediately even if other songs are currently playing
 *          after completing the song stops the player regardless of the continous setting
 * @param isPlaying - if true and playOneTime != true, will enqueue the song to the playlist rather
 *          than immediately playing it, otherwise will play immediately
 */
private static boolean launchFile(final File file, boolean playOneTime, boolean isPlaying) {
    String extension = FilenameUtils.getExtension(file.getName());
    if (extension != null && extension.toLowerCase().contains("torrent")) {
        GUIMediator.instance().openTorrentFile(file, true);
        return false;
    }
    if (GUIMediator.isPlaylistVisible()) {
        if (MediaPlayer.isPlayableFile(file)) {
            if (playOneTime) {
                BackgroundExecutorService.schedule(new Runnable() {

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

                            public void run() {
                                GUIMediator.instance().launchMedia(new MediaSource(file), false);
                            }
                        });
                    }
                });
            } else if (!isPlaying) {
                BackgroundExecutorService.schedule(new Runnable() {

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

                            public void run() {
                                GUIMediator.instance().launchMedia(new MediaSource(file), false);
                            }
                        });
                    }
                });
            } else {
            // PlaylistMediator.getInstance().addFileToPlaylist(file);
            }
            return true;
        }
    }
    GUIMediator.launchFile(file);
    return false;
}
Also used : MediaSource(com.frostwire.gui.player.MediaSource)

Aggregations

MediaSource (com.frostwire.gui.player.MediaSource)9 File (java.io.File)2 Playlist (com.frostwire.alexandria.Playlist)1 ArrayList (java.util.ArrayList)1