Search in sources :

Example 1 with Music

use of me.zhanghai.android.douya.network.api.info.frodo.Music in project Douya by DreaminginCodeZH.

the class ItemIntroductionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Calls ensureSubDecor().
    findViewById(android.R.id.content);
    if (savedInstanceState == null) {
        Intent intent = getIntent();
        CollectableItem item = intent.getParcelableExtra(EXTRA_ITEM);
        Fragment fragment;
        switch(item.getType()) {
            case APP:
                // TODO
                throw new UnsupportedOperationException();
            case BOOK:
                fragment = BookIntroductionFragment.newInstance((Book) item);
                break;
            case EVENT:
                // TODO
                throw new UnsupportedOperationException();
            case GAME:
                fragment = GameIntroductionFragment.newInstance((Game) item);
                break;
            case MOVIE:
            case TV:
                fragment = MovieIntroductionFragment.newInstance((Movie) item);
                break;
            case MUSIC:
                fragment = MusicIntroductionFragment.newInstance((Music) item);
                break;
            default:
                throw new IllegalArgumentException();
        }
        FragmentUtils.add(fragment, this, android.R.id.content);
    }
}
Also used : Movie(me.zhanghai.android.douya.network.api.info.frodo.Movie) CollectableItem(me.zhanghai.android.douya.network.api.info.frodo.CollectableItem) Game(me.zhanghai.android.douya.network.api.info.frodo.Game) Book(me.zhanghai.android.douya.network.api.info.frodo.Book) Music(me.zhanghai.android.douya.network.api.info.frodo.Music) Intent(android.content.Intent) Fragment(androidx.fragment.app.Fragment)

Example 2 with Music

use of me.zhanghai.android.douya.network.api.info.frodo.Music in project Douya by DreaminginCodeZH.

the class PlayMusicService method onHandleIntent.

private void onHandleIntent(Intent intent) {
    Music music = intent.getParcelableExtra(EXTRA_MUSIC);
    boolean hasTrackIndex = intent.hasExtra(EXTRA_TRACK_INDEX);
    int trackIndex = intent.getIntExtra(EXTRA_TRACK_INDEX, 0);
    boolean playOrPause = intent.getBooleanExtra(EXTRA_PLAY_OR_PAUSE, false);
    boolean musicChanged = music.id != getMusicId();
    mMusic = music;
    if (musicChanged) {
        mMediaPlayback.stop();
        // TODO: Use dedicated session activity.
        PendingIntent sessionActivity = PendingIntent.getActivity(this, LongCompat.hashCode(getMusicId()), MusicActivity.makeIntent(mMusic, this), PendingIntent.FLAG_UPDATE_CURRENT);
        mMediaPlayback.setSessionActivity(sessionActivity);
        List<MediaMetadataCompat> mediaMetadatas = Functional.map(mMusic.tracks, (track, index) -> makeMediaMetadata(mMusic, track, index));
        mMediaPlayback.setMediaMetadatas(mediaMetadatas);
        loadMediaMetadataDisplayIconAndAlbumArt(mMusic);
        mMediaPlayback.start();
    }
    if (!hasTrackIndex) {
        mMediaPlayback.skipToQueueItem(0);
        mMediaPlayback.play();
    } else {
        if (mMediaPlayback.getActiveQueueItemIndex() != trackIndex) {
            mMediaPlayback.skipToQueueItem(trackIndex);
        }
        if (playOrPause) {
            mMediaPlayback.play();
        } else {
            mMediaPlayback.pause();
        }
    }
    mMediaNotification.start();
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Music(me.zhanghai.android.douya.network.api.info.frodo.Music) PendingIntent(android.app.PendingIntent)

Example 3 with Music

use of me.zhanghai.android.douya.network.api.info.frodo.Music in project Douya by DreaminginCodeZH.

the class MusicFragment method uncollect.

@Override
public void uncollect() {
    if (!mResource.hasItem()) {
        return;
    }
    Music music = mResource.getItem();
    UncollectItemManager.getInstance().write(music.getType(), music.id, getActivity());
}
Also used : SimpleMusic(me.zhanghai.android.douya.network.api.info.frodo.SimpleMusic) Music(me.zhanghai.android.douya.network.api.info.frodo.Music)

Example 4 with Music

use of me.zhanghai.android.douya.network.api.info.frodo.Music in project Douya by DreaminginCodeZH.

the class MusicActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Calls ensureSubDecor().
    findViewById(android.R.id.content);
    if (savedInstanceState == null) {
        Intent intent = getIntent();
        long musicId = intent.getLongExtra(EXTRA_MUSIC_ID, -1);
        SimpleMusic simpleMusic = intent.getParcelableExtra(EXTRA_SIMPLE_MUSIC);
        Music music = intent.getParcelableExtra(EXTRA_MUSIC);
        FragmentUtils.add(MusicFragment.newInstance(musicId, simpleMusic, music), this, android.R.id.content);
    }
}
Also used : SimpleMusic(me.zhanghai.android.douya.network.api.info.frodo.SimpleMusic) Music(me.zhanghai.android.douya.network.api.info.frodo.Music) SimpleMusic(me.zhanghai.android.douya.network.api.info.frodo.SimpleMusic) Intent(android.content.Intent)

Aggregations

Music (me.zhanghai.android.douya.network.api.info.frodo.Music)4 Intent (android.content.Intent)2 SimpleMusic (me.zhanghai.android.douya.network.api.info.frodo.SimpleMusic)2 PendingIntent (android.app.PendingIntent)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 Fragment (androidx.fragment.app.Fragment)1 Book (me.zhanghai.android.douya.network.api.info.frodo.Book)1 CollectableItem (me.zhanghai.android.douya.network.api.info.frodo.CollectableItem)1 Game (me.zhanghai.android.douya.network.api.info.frodo.Game)1 Movie (me.zhanghai.android.douya.network.api.info.frodo.Movie)1