Search in sources :

Example 6 with Song

use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.

the class FolderPresenter method addFolderToPlayList.

@Override
public void addFolderToPlayList(final Folder folder, PlayList playList) {
    if (folder.getSongs().isEmpty())
        return;
    if (playList.isFavorite()) {
        for (Song song : folder.getSongs()) {
            song.setFavorite(true);
        }
    }
    playList.addSong(folder.getSongs(), 0);
    Subscription subscription = mRepository.update(playList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<PlayList>() {

        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onCompleted() {
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.hideLoading();
            mView.handleError(e);
        }

        @Override
        public void onNext(PlayList playList) {
            RxBus.getInstance().post(new PlayListUpdatedEvent(playList));
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) PlayListUpdatedEvent(io.github.ryanhoo.music.event.PlayListUpdatedEvent) Song(io.github.ryanhoo.music.data.model.Song) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 7 with Song

use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.

the class FileUtils method folderFromDir.

public static Folder folderFromDir(File dir) {
    Folder folder = new Folder(dir.getName(), dir.getAbsolutePath());
    List<Song> songs = musicFiles(dir);
    folder.setSongs(songs);
    folder.setNumOfSongs(songs.size());
    return folder;
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) Folder(io.github.ryanhoo.music.data.model.Folder)

Example 8 with Song

use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.

the class PlaybackService method updateRemoteViews.

private void updateRemoteViews(RemoteViews remoteView) {
    Song currentSong = mPlayer.getPlayingSong();
    if (currentSong != null) {
        remoteView.setTextViewText(R.id.text_view_name, currentSong.getDisplayName());
        remoteView.setTextViewText(R.id.text_view_artist, currentSong.getArtist());
    }
    remoteView.setImageViewResource(R.id.image_view_play_toggle, isPlaying() ? R.drawable.ic_remote_view_pause : R.drawable.ic_remote_view_play);
    Bitmap album = AlbumUtils.parseAlbum(getPlayingSong());
    if (album == null) {
        remoteView.setImageViewResource(R.id.image_view_album, R.mipmap.ic_launcher);
    } else {
        remoteView.setImageViewBitmap(R.id.image_view_album, album);
    }
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) Bitmap(android.graphics.Bitmap)

Example 9 with Song

use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.

the class Player method play.

@Override
public boolean play() {
    if (isPaused) {
        mPlayer.start();
        notifyPlayStatusChanged(true);
        return true;
    }
    if (mPlayList.prepare()) {
        Song song = mPlayList.getCurrentSong();
        try {
            mPlayer.reset();
            mPlayer.setDataSource(song.getPath());
            mPlayer.prepare();
            mPlayer.start();
            notifyPlayStatusChanged(true);
        } catch (IOException e) {
            Log.e(TAG, "play: ", e);
            notifyPlayStatusChanged(false);
            return false;
        }
        return true;
    }
    return false;
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) IOException(java.io.IOException)

Example 10 with Song

use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.

the class Player method playLast.

@Override
public boolean playLast() {
    isPaused = false;
    boolean hasLast = mPlayList.hasLast();
    if (hasLast) {
        Song last = mPlayList.last();
        play();
        notifyPlayLast(last);
        return true;
    }
    return false;
}
Also used : Song(io.github.ryanhoo.music.data.model.Song)

Aggregations

Song (io.github.ryanhoo.music.data.model.Song)18 Subscription (rx.Subscription)4 CompositeSubscription (rx.subscriptions.CompositeSubscription)4 PlayList (io.github.ryanhoo.music.data.model.PlayList)3 Folder (io.github.ryanhoo.music.data.model.Folder)2 File (java.io.File)2 List (java.util.List)2 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 OnClick (butterknife.OnClick)1 FavoriteChangeEvent (io.github.ryanhoo.music.event.FavoriteChangeEvent)1 PlayListUpdatedEvent (io.github.ryanhoo.music.event.PlayListUpdatedEvent)1 PlaySongEvent (io.github.ryanhoo.music.event.PlaySongEvent)1 OnItemClickListener (io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener)1 DefaultDividerDecoration (io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)1 AddToPlayListDialogFragment (io.github.ryanhoo.music.ui.playlist.AddToPlayListDialogFragment)1 IOException (java.io.IOException)1