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();
}
}
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();
}
}
}
}
Aggregations