Search in sources :

Example 11 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class MediaPlayer method isThisBeingPlayed.

public boolean isThisBeingPlayed(PlaylistItem playlistItem) {
    if (isPlayerStoppedClosedFailed()) {
        return false;
    }
    MediaSource currentMedia = getCurrentMedia();
    if (currentMedia == null) {
        return false;
    }
    PlaylistItem currentMediaFile = currentMedia.getPlaylistItem();
    return currentMediaFile != null && playlistItem.equals(currentMediaFile);
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 12 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class MediaPlayerComponent method updateSocialButton.

private void updateSocialButton(final MediaSource currentMedia) {
    SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() {

        private boolean foundSocialLink;

        private String socialLink;

        @Override
        protected Void doInBackground() throws Exception {
            if (currentMedia != null && (currentMedia.getFile() != null || currentMedia.getPlaylistItem() != null)) {
                String commentToParse = "";
                if (currentMedia.getFile() != null) {
                    commentToParse = getCommentFromMP3(currentMedia);
                } else if (currentMedia.getPlaylistItem() != null) {
                    PlaylistItem playlistItem = currentMedia.getPlaylistItem();
                    commentToParse = playlistItem.getTrackComment();
                }
                parseSocialLink(commentToParse);
            }
            return null;
        }

        @Override
        protected void done() {
            if (foundSocialLink) {
                setupSocialButtonAction();
            }
            socialButton.setVisible(foundSocialLink);
        }

        private void setupSocialButtonAction() {
            String artist = getArtistFromMP3(currentMedia);
            if (artist.equals("")) {
                artist = I18n.tr("this artist(s)");
            }
            if (socialLink.contains("facebook")) {
                socialButton.init(I18n.tr("Open Facebook page of") + " " + artist, "FACEBOOK", "FACEBOOK");
            } else if (socialLink.contains("twitter")) {
                socialButton.init(I18n.tr("Open Twitter page of") + " " + artist, "TWITTER", "TWITTER");
            }
            removeSocialButtonActionListeners();
            socialButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    GUIMediator.openURL(socialLink);
                }
            });
        }

        private void removeSocialButtonActionListeners() {
            ActionListener[] actionListeners = socialButton.getActionListeners();
            if (actionListeners != null && actionListeners.length > 0) {
                for (ActionListener al : actionListeners) {
                    socialButton.removeActionListener(al);
                }
            }
        }

        private void parseSocialLink(String commentToParse) {
            if (!StringUtils.isNullOrEmpty(commentToParse)) {
                String trimmedComment = commentToParse.toLowerCase().trim();
                Matcher facebookMatcher = facebookURLPattern.matcher(trimmedComment);
                if (facebookMatcher.find()) {
                    socialLink = facebookMatcher.group(0);
                } else {
                    Matcher twitterURLMatcher = twitterURLPattern.matcher(trimmedComment);
                    if (twitterURLMatcher.find()) {
                        socialLink = twitterURLMatcher.group(0);
                    } else {
                        Matcher twitterUsernameMatcher = twitterUsernamePattern.matcher(trimmedComment);
                        if (twitterUsernameMatcher.find()) {
                            String tweep = twitterUsernameMatcher.group(0).trim();
                            socialLink = "https://twitter.com/" + tweep.substring(1);
                        }
                    }
                }
                foundSocialLink = !StringUtils.isNullOrEmpty(socialLink);
            }
        }
    };
    swingWorker.execute();
}
Also used : Matcher(java.util.regex.Matcher) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 13 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class PlaylistItemStarEditor method getTableCellEditorComponent.

public Component getTableCellEditorComponent(final JTable table, final Object value, boolean isSelected, int row, int column) {
    final LibraryPlaylistsTableDataLine line = ((PlaylistItemProperty<?>) value).getLine();
    final JLabel component = (JLabel) new PlaylistItemStarRenderer().getTableCellRendererComponent(table, value, isSelected, true, row, column);
    component.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (!((PlaylistItemProperty<?>) value).exists()) {
                return;
            }
            PlaylistItem playlistItem = line.getInitializeObject();
            if (line.getInitializeObject().isStarred()) {
                playlistItem.setStarred(false);
                playlistItem.save();
                component.setIcon(starOff);
            } else {
                playlistItem.setStarred(true);
                playlistItem.save();
                component.setIcon(starOn);
            }
        }
    });
    if (!((PlaylistItemStarProperty) value).exists()) {
        component.setIcon(exclamation);
    } else if (line.getInitializeObject().isStarred()) {
        component.setIcon(starOn);
    } else {
        component.setIcon(starOff);
    }
    return component;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 14 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryPlaylistsTableMediator method updatePlaylistComponentHeader.

private void updatePlaylistComponentHeader(String lyrics) {
    JPanel playlistHeaderRow = new JPanel(new MigLayout("insets 10, fillx", "[][grow][]"));
    LibraryCoverArtPanel artWorkLabel = new LibraryCoverArtPanel();
    if (currentPlaylist == null) {
        return;
    }
    if (!currentPlaylist.isStarred()) {
        PlaylistItem playlistItem = currentPlaylist.getItems().get(0);
        if (playlistItem != null) {
            TagsReader tagsReader = new TagsReader(new File(playlistItem.getFilePath()));
            artWorkLabel.setTagsReader(tagsReader).asyncRetrieveImage();
        }
    }
    // left
    Dimension artDimensions = new Dimension(210, 210);
    artWorkLabel.setPreferredSize(artDimensions);
    artWorkLabel.setMinimumSize(artDimensions);
    artWorkLabel.setMaximumSize(artDimensions);
    playlistHeaderRow.add(artWorkLabel);
    // center
    JPanel centerContainer = new JPanel(new MigLayout("fillx, wrap 1"));
    JLabel playlistSectionTitle = new JLabel(I18n.tr("Playlist"));
    // Replace this for a text edit or show a dialog to rename it
    JLabel playlistTitle = new JLabel(currentPlaylist.getName());
    Font font = new Font("Helvetica", Font.BOLD, 30);
    playlistTitle.setFont(font);
    JLabel duration = new JLabel(LibraryUtils.getPlaylistDurationInDDHHMMSS(currentPlaylist) + ", " + currentPlaylist.getItems().size() + " " + I18n.tr("tracks"));
    centerContainer.add(playlistSectionTitle, "wrap");
    centerContainer.add(playlistTitle, "wrap");
    centerContainer.add(duration);
    playlistHeaderRow.add(centerContainer, "alignx left, aligny top, growx, pushx");
    if (lyrics != null && !lyrics.isEmpty()) {
        JPanel lyricsPanel = createLyricsPanel(lyrics);
        playlistHeaderRow.add(lyricsPanel, "aligny top");
    }
    mainContainer.removeAll();
    mainContainer.add(playlistHeaderRow, "wrap, growx");
    mainContainer.add(super.getComponent(), "grow");
    mainContainer.invalidate();
    mainContainer.repaint();
    mainContainer.updateUI();
}
Also used : MigLayout(net.miginfocom.swing.MigLayout) TagsReader(com.frostwire.gui.library.tags.TagsReader) File(java.io.File) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 15 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryPlaylistsTableMediator method updateTableItems.

/**
 * 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 updateTableItems(Playlist playlist) {
    if (playlist == null) {
        return;
    }
    currentPlaylist = playlist;
    List<PlaylistItem> items = currentPlaylist.getItems();
    clearTable();
    for (final PlaylistItem item : items) {
        GUIMediator.safeInvokeLater(new Runnable() {

            @Override
            public void run() {
                addUnsorted(item);
            }
        });
    }
    forceResort();
    GUIMediator.safeInvokeLater(new Runnable() {

        @Override
        public void run() {
            updatePlaylistComponentHeader(null);
            TABLE.requestFocusInWindow();
        }
    });
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Aggregations

PlaylistItem (com.frostwire.alexandria.PlaylistItem)28 ArrayList (java.util.ArrayList)8 File (java.io.File)7 Transferable (java.awt.datatransfer.Transferable)4 Playlist (com.frostwire.alexandria.Playlist)3 Item (com.frostwire.gui.library.LibraryPlaylistsTableTransferable.Item)3 List (java.util.List)3 TagsReader (com.frostwire.gui.library.tags.TagsReader)2 SkinMenuItem (com.frostwire.gui.theme.SkinMenuItem)2 SkinPopupMenu (com.frostwire.gui.theme.SkinPopupMenu)2 MigLayout (net.miginfocom.swing.MigLayout)2 TagsData (com.frostwire.gui.library.tags.TagsData)1 IsoFile (com.frostwire.mp4.IsoFile)1 FileTransferable (com.limegroup.gnutella.gui.dnd.FileTransferable)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 HashSet (java.util.HashSet)1