Search in sources :

Example 1 with DownloadFile

use of org.moire.ultrasonic.service.DownloadFile 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 DownloadFile

use of org.moire.ultrasonic.service.DownloadFile 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 DownloadFile

use of org.moire.ultrasonic.service.DownloadFile 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 DownloadFile

use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.

the class CacheCleaner method findFilesToNotDelete.

private Set<File> findFilesToNotDelete() {
    Set<File> filesToNotDelete = new HashSet<File>(5);
    for (DownloadFile downloadFile : downloadService.getDownloads()) {
        filesToNotDelete.add(downloadFile.getPartialFile());
        filesToNotDelete.add(downloadFile.getCompleteFile());
    }
    filesToNotDelete.add(FileUtil.getMusicDirectory(context));
    return filesToNotDelete;
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) DownloadFile(org.moire.ultrasonic.service.DownloadFile) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with DownloadFile

use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.

the class DownloadActivity method menuItemSelected.

private boolean menuItemSelected(final int menuItemId, final DownloadFile song) {
    Entry entry = null;
    if (song != null) {
        entry = song.getSong();
    }
    switch(menuItemId) {
        case R.id.menu_show_artist:
            if (entry == null) {
                return false;
            }
            if (Util.getShouldUseId3Tags(DownloadActivity.this)) {
                Intent intent = new Intent(DownloadActivity.this, SelectAlbumActivity.class);
                intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getArtistId());
                intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getArtist());
                intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.getArtistId());
                intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true);
                startActivityForResultWithoutTransition(DownloadActivity.this, intent);
            }
            return true;
        case R.id.menu_show_album:
            if (entry == null) {
                return false;
            }
            Intent intent = new Intent(this, SelectAlbumActivity.class);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getParent());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getAlbum());
            startActivityForResultWithoutTransition(this, intent);
            return true;
        case R.id.menu_lyrics:
            if (entry == null) {
                return false;
            }
            intent = new Intent(this, LyricsActivity.class);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, entry.getArtist());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, entry.getTitle());
            startActivityForResultWithoutTransition(this, intent);
            return true;
        case R.id.menu_remove:
            getDownloadService().remove(song);
            onDownloadListChanged();
            return true;
        case R.id.menu_item_screen_on_off:
            if (getDownloadService().getKeepScreenOn()) {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                getDownloadService().setKeepScreenOn(false);
            } else {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                getDownloadService().setKeepScreenOn(true);
            }
            return true;
        case R.id.menu_shuffle:
            getDownloadService().shuffle();
            Util.toast(this, R.string.download_menu_shuffle_notification);
            return true;
        case R.id.menu_item_equalizer:
            startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
            return true;
        case R.id.menu_item_visualizer:
            final boolean active = !visualizerView.isActive();
            visualizerView.setActive(active);
            if (!visualizerView.isActive()) {
                visualizerViewLayout.setVisibility(View.GONE);
            } else {
                visualizerViewLayout.setVisibility(View.VISIBLE);
            }
            getDownloadService().setShowVisualization(visualizerView.isActive());
            Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
            return true;
        case R.id.menu_item_jukebox:
            final boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
            getDownloadService().setJukeboxEnabled(jukeboxEnabled);
            Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
            return true;
        case R.id.menu_item_toggle_list:
            toggleFullScreenAlbumArt();
            return true;
        case R.id.menu_item_clear_playlist:
            getDownloadService().setShufflePlayEnabled(false);
            getDownloadService().clear();
            onDownloadListChanged();
            return true;
        case R.id.menu_item_save_playlist:
            if (!getDownloadService().getSongs().isEmpty()) {
                showDialog(DIALOG_SAVE_PLAYLIST);
            }
            return true;
        case R.id.menu_item_star:
            if (currentSong == null) {
                return true;
            }
            final boolean isStarred = currentSong.getStarred();
            final String id = currentSong.getId();
            if (isStarred) {
                starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow));
                currentSong.setStarred(false);
            } else {
                starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full));
                currentSong.setStarred(true);
            }
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
                    try {
                        if (isStarred) {
                            musicService.unstar(id, null, null, DownloadActivity.this, null);
                        } else {
                            musicService.star(id, null, null, DownloadActivity.this, null);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }).start();
            return true;
        case R.id.menu_item_bookmark_set:
            if (currentSong == null) {
                return true;
            }
            final String songId = currentSong.getId();
            final int playerPosition = getDownloadService().getPlayerPosition();
            currentSong.setBookmarkPosition(playerPosition);
            String bookmarkTime = Util.formatTotalDuration(playerPosition, true);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
                    try {
                        musicService.createBookmark(songId, playerPosition, DownloadActivity.this, null);
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }).start();
            String msg = getResources().getString(R.string.download_bookmark_set_at_position, bookmarkTime);
            Util.toast(DownloadActivity.this, msg);
            return true;
        case R.id.menu_item_bookmark_delete:
            if (currentSong == null) {
                return true;
            }
            final String bookmarkSongId = currentSong.getId();
            currentSong.setBookmarkPosition(0);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
                    try {
                        musicService.deleteBookmark(bookmarkSongId, DownloadActivity.this, null);
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }).start();
            Util.toast(DownloadActivity.this, R.string.download_bookmark_removed);
            return true;
        case R.id.menu_item_share:
            DownloadService downloadService = getDownloadService();
            List<Entry> entries = new ArrayList<Entry>();
            if (downloadService != null) {
                List<DownloadFile> downloadServiceSongs = downloadService.getSongs();
                if (downloadServiceSongs != null) {
                    for (DownloadFile downloadFile : downloadServiceSongs) {
                        if (downloadFile != null) {
                            Entry playlistEntry = downloadFile.getSong();
                            if (playlistEntry != null) {
                                entries.add(playlistEntry);
                            }
                        }
                    }
                }
            }
            createShare(entries);
            return true;
        default:
            return false;
    }
}
Also used : MusicService(org.moire.ultrasonic.service.MusicService) DownloadFile(org.moire.ultrasonic.service.DownloadFile) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Point(android.graphics.Point) DownloadService(org.moire.ultrasonic.service.DownloadService) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry)

Aggregations

DownloadFile (org.moire.ultrasonic.service.DownloadFile)14 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)6 File (java.io.File)4 DownloadService (org.moire.ultrasonic.service.DownloadService)4 Intent (android.content.Intent)3 Point (android.graphics.Point)3 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)3 PendingIntent (android.app.PendingIntent)2 MenuItem (android.view.MenuItem)2 AdapterView (android.widget.AdapterView)2 SongListAdapter (org.moire.ultrasonic.view.SongListAdapter)2 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 Drawable (android.graphics.drawable.Drawable)1 MenuInflater (android.view.MenuInflater)1 ListAdapter (android.widget.ListAdapter)1 DragSortListView (com.mobeta.android.dslv.DragSortListView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PlayerState (org.moire.ultrasonic.domain.PlayerState)1 MusicService (org.moire.ultrasonic.service.MusicService)1