Search in sources :

Example 1 with Entry

use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.

the class Util method broadcastA2dpMetaDataChange.

public static void broadcastA2dpMetaDataChange(Context context, DownloadService downloadService) {
    if (!Util.getShouldSendBluetoothNotifications(context)) {
        return;
    }
    Entry song = null;
    Intent avrcpIntent = new Intent(CM_AVRCP_METADATA_CHANGED);
    if (downloadService != null) {
        DownloadFile entry = downloadService.getCurrentPlaying();
        if (entry != null) {
            song = entry.getSong();
        }
    }
    if (downloadService == null || song == null) {
        avrcpIntent.putExtra("track", "");
        avrcpIntent.putExtra("track_name", "");
        avrcpIntent.putExtra("artist", "");
        avrcpIntent.putExtra("artist_name", "");
        avrcpIntent.putExtra("album", "");
        avrcpIntent.putExtra("album_name", "");
        avrcpIntent.putExtra("album_artist", "");
        avrcpIntent.putExtra("album_artist_name", "");
        if (Util.getShouldSendBluetoothAlbumArt(context)) {
            avrcpIntent.putExtra("coverart", (Parcelable) null);
            avrcpIntent.putExtra("cover", (Parcelable) null);
        }
        avrcpIntent.putExtra("ListSize", (long) 0);
        avrcpIntent.putExtra("id", (long) 0);
        avrcpIntent.putExtra("duration", (long) 0);
        avrcpIntent.putExtra("position", (long) 0);
    } else {
        if (song != currentSong) {
            currentSong = song;
        }
        String title = song.getTitle();
        String artist = song.getArtist();
        String album = song.getAlbum();
        Integer duration = song.getDuration();
        Integer listSize = downloadService.getDownloads().size();
        Integer id = downloadService.getCurrentPlayingIndex() + 1;
        Integer playerPosition = downloadService.getPlayerPosition();
        avrcpIntent.putExtra("track", title);
        avrcpIntent.putExtra("track_name", title);
        avrcpIntent.putExtra("artist", artist);
        avrcpIntent.putExtra("artist_name", artist);
        avrcpIntent.putExtra("album", album);
        avrcpIntent.putExtra("album_name", album);
        avrcpIntent.putExtra("album_artist", artist);
        avrcpIntent.putExtra("album_artist_name", artist);
        if (Util.getShouldSendBluetoothAlbumArt(context)) {
            File albumArtFile = FileUtil.getAlbumArtFile(context, song);
            avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
            avrcpIntent.putExtra("cover", albumArtFile.getAbsolutePath());
        }
        avrcpIntent.putExtra("position", (long) playerPosition);
        avrcpIntent.putExtra("id", (long) id);
        avrcpIntent.putExtra("ListSize", (long) listSize);
        if (duration != null) {
            avrcpIntent.putExtra("duration", (long) duration);
        }
    }
    context.sendBroadcast(avrcpIntent);
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) DownloadFile(org.moire.ultrasonic.service.DownloadFile) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DownloadFile(org.moire.ultrasonic.service.DownloadFile) File(java.io.File)

Example 2 with Entry

use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.

the class Util method broadcastA2dpPlayStatusChange.

public static void broadcastA2dpPlayStatusChange(Context context, PlayerState state, DownloadService downloadService) {
    if (!Util.getShouldSendBluetoothNotifications(context) || downloadService == null) {
        return;
    }
    DownloadFile currentPlaying = downloadService.getCurrentPlaying();
    if (currentPlaying != null) {
        Intent avrcpIntent = new Intent(CM_AVRCP_PLAYSTATE_CHANGED);
        Entry song = currentPlaying.getSong();
        if (song == null) {
            return;
        }
        if (song != currentSong) {
            currentSong = song;
        }
        String title = song.getTitle();
        String artist = song.getArtist();
        String album = song.getAlbum();
        Integer duration = song.getDuration();
        Integer listSize = downloadService.getDownloads().size();
        Integer id = downloadService.getCurrentPlayingIndex() + 1;
        Integer playerPosition = downloadService.getPlayerPosition();
        avrcpIntent.putExtra("track", title);
        avrcpIntent.putExtra("track_name", title);
        avrcpIntent.putExtra("artist", artist);
        avrcpIntent.putExtra("artist_name", artist);
        avrcpIntent.putExtra("album", album);
        avrcpIntent.putExtra("album_name", album);
        avrcpIntent.putExtra("album_artist", artist);
        avrcpIntent.putExtra("album_artist_name", artist);
        if (Util.getShouldSendBluetoothAlbumArt(context)) {
            File albumArtFile = FileUtil.getAlbumArtFile(context, song);
            avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
            avrcpIntent.putExtra("cover", albumArtFile.getAbsolutePath());
        }
        avrcpIntent.putExtra("position", (long) playerPosition);
        avrcpIntent.putExtra("id", (long) id);
        avrcpIntent.putExtra("ListSize", (long) listSize);
        if (duration != null) {
            avrcpIntent.putExtra("duration", (long) duration);
        }
        switch(state) {
            case STARTED:
                avrcpIntent.putExtra("playing", true);
                break;
            case STOPPED:
                avrcpIntent.putExtra("playing", false);
                break;
            case PAUSED:
                avrcpIntent.putExtra("playing", false);
                break;
            case COMPLETED:
                avrcpIntent.putExtra("playing", false);
                break;
            default:
                // No need to broadcast.
                return;
        }
        context.sendBroadcast(avrcpIntent);
    }
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) DownloadFile(org.moire.ultrasonic.service.DownloadFile) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) DownloadFile(org.moire.ultrasonic.service.DownloadFile) File(java.io.File)

Example 3 with Entry

use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.

the class SubsonicTabActivity method showNowPlaying.

public void showNowPlaying() {
    this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            new SilentBackgroundTask<Void>(SubsonicTabActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    if (!Util.getShowNowPlayingPreference(SubsonicTabActivity.this)) {
                        hideNowPlaying();
                        return null;
                    }
                    nowPlayingView = findViewById(R.id.now_playing);
                    if (nowPlayingView != null) {
                        final DownloadService downloadService = DownloadServiceImpl.getInstance();
                        if (downloadService != null) {
                            PlayerState playerState = downloadService.getPlayerState();
                            if (playerState.equals(PlayerState.PAUSED) || playerState.equals(PlayerState.STARTED)) {
                                DownloadFile file = downloadService.getCurrentPlaying();
                                if (file != null) {
                                    final Entry song = file.getSong();
                                    showNowPlaying(SubsonicTabActivity.this, downloadService, song, playerState);
                                }
                            } else {
                                hideNowPlaying();
                            }
                        }
                    }
                    return null;
                }

                @Override
                protected void done(Void result) {
                }
            }.execute();
        }
    });
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) DownloadFile(org.moire.ultrasonic.service.DownloadFile) PlayerState(org.moire.ultrasonic.domain.PlayerState) SilentBackgroundTask(org.moire.ultrasonic.util.SilentBackgroundTask) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 4 with Entry

use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.

the class SubsonicTabActivity method downloadRecursively.

protected void downloadRecursively(final String id, final String name, final boolean isShare, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background, final boolean playNext, final boolean unpin, final boolean isArtist) {
    ModalBackgroundTask<List<Entry>> task = new ModalBackgroundTask<List<Entry>>(this, false) {

        private static final int MAX_SONGS = 500;

        @Override
        protected List<Entry> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            List<Entry> songs = new LinkedList<Entry>();
            MusicDirectory root;
            if (!Util.isOffline(SubsonicTabActivity.this) && isArtist && Util.getShouldUseId3Tags(SubsonicTabActivity.this)) {
                getSongsForArtist(id, songs);
            } else {
                if (isDirectory) {
                    root = !Util.isOffline(SubsonicTabActivity.this) && Util.getShouldUseId3Tags(SubsonicTabActivity.this) ? musicService.getAlbum(id, name, false, SubsonicTabActivity.this, this) : musicService.getMusicDirectory(id, name, false, SubsonicTabActivity.this, this);
                } else if (isShare) {
                    root = new MusicDirectory();
                    List<Share> shares = musicService.getShares(true, SubsonicTabActivity.this, this);
                    for (Share share : shares) {
                        if (share.getId().equals(id)) {
                            for (Entry entry : share.getEntries()) {
                                root.addChild(entry);
                            }
                            break;
                        }
                    }
                } else {
                    root = musicService.getPlaylist(id, name, SubsonicTabActivity.this, this);
                }
                getSongsRecursively(root, songs);
            }
            return songs;
        }

        private void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
            if (songs.size() > MAX_SONGS) {
                return;
            }
            for (Entry song : parent.getChildren(false, true)) {
                if (!song.isVideo()) {
                    songs.add(song);
                }
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            for (Entry dir : parent.getChildren(true, false)) {
                MusicDirectory root;
                root = !Util.isOffline(SubsonicTabActivity.this) && Util.getShouldUseId3Tags(SubsonicTabActivity.this) ? musicService.getAlbum(dir.getId(), dir.getTitle(), false, SubsonicTabActivity.this, this) : musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, SubsonicTabActivity.this, this);
                getSongsRecursively(root, songs);
            }
        }

        private void getSongsForArtist(String id, Collection<Entry> songs) throws Exception {
            if (songs.size() > MAX_SONGS) {
                return;
            }
            MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
            MusicDirectory artist = musicService.getArtist(id, "", false, SubsonicTabActivity.this, this);
            for (Entry album : artist.getChildren()) {
                MusicDirectory albumDirectory = musicService.getAlbum(album.getId(), "", false, SubsonicTabActivity.this, this);
                for (Entry song : albumDirectory.getChildren()) {
                    if (!song.isVideo()) {
                        songs.add(song);
                    }
                }
            }
        }

        @Override
        protected void done(List<Entry> songs) {
            if (Util.getShouldSortByDisc(SubsonicTabActivity.this)) {
                Collections.sort(songs, new EntryByDiscAndTrackComparator());
            }
            DownloadService downloadService = getDownloadService();
            if (!songs.isEmpty() && downloadService != null) {
                if (!append && !playNext && !unpin && !background) {
                    downloadService.clear();
                }
                warnIfNetworkOrStorageUnavailable();
                if (!background) {
                    if (unpin) {
                        downloadService.unpin(songs);
                    } else {
                        downloadService.download(songs, save, autoplay, playNext, shuffle, false);
                        if (!append && Util.getShouldTransitionOnPlaybackPreference(SubsonicTabActivity.this)) {
                            startActivityForResultWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class);
                        }
                    }
                } else {
                    if (unpin) {
                        downloadService.unpin(songs);
                    } else {
                        downloadService.downloadBackground(songs, save);
                    }
                }
            }
        }
    };
    task.execute();
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MusicService(org.moire.ultrasonic.service.MusicService) EntryByDiscAndTrackComparator(org.moire.ultrasonic.util.EntryByDiscAndTrackComparator) ModalBackgroundTask(org.moire.ultrasonic.util.ModalBackgroundTask) LinkedList(java.util.LinkedList) DownloadService(org.moire.ultrasonic.service.DownloadService) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Share(org.moire.ultrasonic.domain.Share)

Example 5 with Entry

use of org.moire.ultrasonic.domain.MusicDirectory.Entry in project ultrasonic by ultrasonic.

the class BookmarkActivity method selectAll.

private void selectAll(boolean selected, boolean toast) {
    int count = albumListView.getCount();
    int selectedCount = 0;
    for (int i = 0; i < count; i++) {
        MusicDirectory.Entry entry = (MusicDirectory.Entry) albumListView.getItemAtPosition(i);
        if (entry != null && !entry.isDirectory() && !entry.isVideo()) {
            albumListView.setItemChecked(i, selected);
            selectedCount++;
        }
    }
    // Display toast: N tracks selected / N tracks unselected
    if (toast) {
        int toastResId = selected ? R.string.select_album_n_selected : R.string.select_album_n_unselected;
        Util.toast(this, getString(toastResId, selectedCount));
    }
    enableButtons();
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry)

Aggregations

Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)14 Intent (android.content.Intent)6 DownloadFile (org.moire.ultrasonic.service.DownloadFile)5 AdapterView (android.widget.AdapterView)4 ArrayList (java.util.ArrayList)4 DownloadService (org.moire.ultrasonic.service.DownloadService)4 PendingIntent (android.app.PendingIntent)3 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)3 MusicService (org.moire.ultrasonic.service.MusicService)3 View (android.view.View)2 ListView (android.widget.ListView)2 File (java.io.File)2 Artist (org.moire.ultrasonic.domain.Artist)2 Share (org.moire.ultrasonic.domain.Share)2 SuppressLint (android.annotation.SuppressLint)1 Notification (android.app.Notification)1 Bitmap (android.graphics.Bitmap)1 Point (android.graphics.Point)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MenuInflater (android.view.MenuInflater)1