Search in sources :

Example 6 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onTrackSelected.

////////////////////////////////////////////////////////////////////////////////////////////////
/*
     * Methods for playing selected songs
     * onTrackSelected -> Used to stream tracks from soundcloud
     * onLocalTrackSelected -> Used to play local songs
     */
public void onTrackSelected(int position) {
    isReloaded = false;
    HideBottomFakeToolbar();
    if (!queueCall) {
        CommonUtils.hideKeyboard(this);
        searchView.setQuery("", false);
        searchView.setIconified(true);
        new Thread(new CancelCall()).start();
        isPlayerVisible = true;
        PlayerFragment frag = playerFragment;
        android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
        PlayerFragment newFragment = new PlayerFragment();
        if (frag == null) {
            playerFragment = newFragment;
            int flag = 0;
            for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                    flag = 1;
                    isFavourite = true;
                    break;
                }
            }
            if (flag == 0) {
                isFavourite = false;
            }
            playerFragment.localIsPlaying = false;
            playerFragment.track = selectedTrack;
            fm.beginTransaction().setCustomAnimations(R.anim.slide_up, R.anim.slide_down, R.anim.slide_up, R.anim.slide_down).add(R.id.player_frag_container, newFragment, "player").show(newFragment).addToBackStack(null).commitAllowingStateLoss();
        } else {
            if (playerFragment.track != null && !playerFragment.localIsPlaying && selectedTrack.getTitle() == playerFragment.track.getTitle()) {
            } else {
                int flag = 0;
                for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                    UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                    if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                        flag = 1;
                        isFavourite = true;
                        break;
                    }
                }
                if (flag == 0) {
                    isFavourite = false;
                }
                playerFragment.localIsPlaying = false;
                playerFragment.track = selectedTrack;
                frag.refresh();
            }
        }
        if (!isQueueVisible)
            showPlayer();
    } else {
        PlayerFragment frag = playerFragment;
        playerFragment.localIsPlaying = false;
        playerFragment.track = selectedTrack;
        int flag = 0;
        for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
            UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
            if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                flag = 1;
                isFavourite = true;
                break;
            }
        }
        if (flag == 0) {
            isFavourite = false;
        }
        frag.refresh();
    }
    if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
        playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
        playerFragment.snappyRecyclerView.setTransparency();
    }
    QueueFragment qFrag = (QueueFragment) fragMan.findFragmentByTag("queue");
    if (qFrag != null) {
        qFrag.updateQueueAdapter();
    }
    UnifiedTrack track = new UnifiedTrack(false, null, playerFragment.track);
    for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
        if (!recentlyPlayed.getRecentlyPlayed().get(i).getType() && recentlyPlayed.getRecentlyPlayed().get(i).getStreamTrack().getTitle().equals(track.getStreamTrack().getTitle())) {
            recentlyPlayed.getRecentlyPlayed().remove(i);
            //                rAdapter.notifyItemRemoved(i);
            break;
        }
    }
    recentlyPlayed.getRecentlyPlayed().add(0, track);
    if (recentlyPlayed.getRecentlyPlayed().size() > 50) {
        recentlyPlayed.getRecentlyPlayed().remove(50);
    }
    recentsRecycler.setVisibility(View.VISIBLE);
    recentsNothingText.setVisibility(View.INVISIBLE);
    continuePlayingList.clear();
    for (int i = 0; i < Math.min(10, recentlyPlayed.getRecentlyPlayed().size()); i++) {
        continuePlayingList.add(recentlyPlayed.getRecentlyPlayed().get(i));
    }
    rAdapter.notifyDataSetChanged();
    refreshHeaderImages();
    RecentsFragment rFrag = (RecentsFragment) fragMan.findFragmentByTag("recent");
    if (rFrag != null && rFrag.rtAdpater != null) {
        rFrag.rtAdpater.notifyDataSetChanged();
    }
}
Also used : UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecentsFragment(com.sdsmdg.harjot.MusicDNA.fragments.RecentsFragment.RecentsFragment) QueueFragment(com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment) TextPaint(android.text.TextPaint) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Example 7 with PlayerFragment

use of com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment in project MusicDNA by harjot-oberai.

the class HomeActivity method onHeadsetPlayPauseClicked.

@Override
public void onHeadsetPlayPauseClicked() {
    PlayerFragment pFrag = getPlayerFragment();
    if (pFrag != null && !isReloaded) {
        if (pFrag.mMediaPlayer != null && pFrag.mMediaPlayer.isPlaying()) {
            if (pFrag.isReplayIconVisible) {
                hasQueueEnded = true;
                onComplete();
            } else {
                if (!pFrag.pauseClicked) {
                    pFrag.pauseClicked = true;
                }
                pFrag.togglePlayPause();
            }
        }
    }
}
Also used : PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Aggregations

PlayerFragment (com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)7 QueueFragment (com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment)4 TextPaint (android.text.TextPaint)3 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)3 Handler (android.os.Handler)2 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ServiceConnection (android.content.ServiceConnection)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Canvas (android.graphics.Canvas)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MediaMetadata (android.media.MediaMetadata)1 Rating (android.media.Rating)1 MediaSession (android.media.session.MediaSession)1 PlaybackState (android.media.session.PlaybackState)1 IBinder (android.os.IBinder)1 NavigationView (android.support.design.widget.NavigationView)1