Search in sources :

Example 1 with Song

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

the class MusicPlayerFragment method onFavoriteToggleAction.

@OnClick(R.id.button_favorite_toggle)
public void onFavoriteToggleAction(View view) {
    if (mPlayer == null)
        return;
    Song currentSong = mPlayer.getPlayingSong();
    if (currentSong != null) {
        view.setEnabled(false);
        mPresenter.setSongAsFavorite(currentSong, !currentSong.isFavorite());
    }
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) OnClick(butterknife.OnClick)

Example 2 with Song

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

the class Player method playNext.

@Override
public boolean playNext() {
    isPaused = false;
    boolean hasNext = mPlayList.hasNext(false);
    if (hasNext) {
        Song next = mPlayList.next();
        play();
        notifyPlayNext(next);
        return true;
    }
    return false;
}
Also used : Song(io.github.ryanhoo.music.data.model.Song)

Example 3 with Song

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

the class Player method onCompletion.

// Listeners
@Override
public void onCompletion(MediaPlayer mp) {
    Song next = null;
    // There is only one limited play mode which is list, player should be stopped when hitting the list end
    if (mPlayList.getPlayMode() == PlayMode.LIST && mPlayList.getPlayingIndex() == mPlayList.getNumOfSongs() - 1) {
    // In the end of the list
    // Do nothing, just deliver the callback
    } else if (mPlayList.getPlayMode() == PlayMode.SINGLE) {
        next = mPlayList.getCurrentSong();
        play();
    } else {
        boolean hasNext = mPlayList.hasNext(true);
        if (hasNext) {
            next = mPlayList.next();
            play();
        }
    }
    notifyComplete(next);
}
Also used : Song(io.github.ryanhoo.music.data.model.Song)

Example 4 with Song

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

the class AllLocalMusicFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);
    mAdapter = new LocalMusicAdapter(getActivity(), null);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            Song song = mAdapter.getItem(position);
            RxBus.getInstance().post(new PlaySongEvent(song));
        }
    });
    recyclerView.setAdapter(mAdapter);
    recyclerView.addItemDecoration(new DefaultDividerDecoration());
    fastScroller.setRecyclerView(recyclerView);
    new LocalMusicPresenter(AppRepository.getInstance(), this).subscribe();
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) OnItemClickListener(io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener) PlaySongEvent(io.github.ryanhoo.music.event.PlaySongEvent) DefaultDividerDecoration(io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)

Example 5 with Song

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

the class FolderPresenter method refreshFolder.

@Override
public void refreshFolder(final Folder folder) {
    Subscription subscription = Observable.just(FileUtils.musicFiles(new File(folder.getPath()))).flatMap(new Func1<List<Song>, Observable<Folder>>() {

        @Override
        public Observable<Folder> call(List<Song> songs) {
            folder.setSongs(songs);
            folder.setNumOfSongs(songs.size());
            return mRepository.update(folder);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Folder>() {

        @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(Folder folder) {
            mView.onFolderUpdated(folder);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) List(java.util.List) PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) Func1(rx.functions.Func1) Folder(io.github.ryanhoo.music.data.model.Folder) File(java.io.File)

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