use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method addAlbumToQueue.
@Override
public void addAlbumToQueue() {
List<LocalTrack> list = tempAlbum.getAlbumSongs();
for (LocalTrack lt : list) {
HomeActivity.queue.addToQueue(new UnifiedTrack(true, lt, null));
}
if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
playerFragment.snappyRecyclerView.setTransparency();
}
Toast.makeText(ctx, "Added " + list.size() + " song(s) to queue", Toast.LENGTH_SHORT).show();
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method getLocalSongs.
private void getLocalSongs() {
localTrackList.clear();
recentlyAddedTrackList.clear();
finalLocalSearchResultList.clear();
finalRecentlyAddedTrackSearchResultList.clear();
albums.clear();
finalAlbums.clear();
artists.clear();
finalArtists.clear();
ContentResolver musicResolver = this.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, MediaStore.MediaColumns.DATE_ADDED + " DESC");
if (musicCursor != null && musicCursor.moveToFirst()) {
// get columns
int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int albumColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int pathColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
int durationColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
// add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisAlbum = musicCursor.getString(albumColumn);
String path = musicCursor.getString(pathColumn);
long duration = musicCursor.getLong(durationColumn);
if (duration > 10000) {
LocalTrack lt = new LocalTrack(thisId, thisTitle, thisArtist, thisAlbum, path, duration);
localTrackList.add(lt);
finalLocalSearchResultList.add(lt);
if (recentlyAddedTrackList.size() <= 50) {
recentlyAddedTrackList.add(lt);
finalRecentlyAddedTrackSearchResultList.add(lt);
}
int pos;
if (thisAlbum != null) {
pos = checkAlbum(thisAlbum);
if (pos != -1) {
albums.get(pos).getAlbumSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Album ab = new Album(thisAlbum, llt);
albums.add(ab);
}
if (pos != -1) {
finalAlbums.get(pos).getAlbumSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Album ab = new Album(thisAlbum, llt);
finalAlbums.add(ab);
}
}
if (thisArtist != null) {
pos = checkArtist(thisArtist);
if (pos != -1) {
artists.get(pos).getArtistSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Artist ab = new Artist(thisArtist, llt);
artists.add(ab);
}
if (pos != -1) {
finalArtists.get(pos).getArtistSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Artist ab = new Artist(thisArtist, llt);
finalArtists.add(ab);
}
}
File f = new File(path);
String dirName = f.getParentFile().getName();
if (getFolder(dirName) == null) {
MusicFolder mf = new MusicFolder(dirName);
mf.getLocalTracks().add(lt);
allMusicFolders.getMusicFolders().add(mf);
} else {
getFolder(dirName).getLocalTracks().add(lt);
}
}
} while (musicCursor.moveToNext());
}
if (musicCursor != null)
musicCursor.close();
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
try {
if (localTrackList.size() > 0) {
Collections.sort(localTrackList, new LocalMusicComparator());
Collections.sort(finalLocalSearchResultList, new LocalMusicComparator());
}
if (albums.size() > 0) {
Collections.sort(albums, new AlbumComparator());
Collections.sort(finalAlbums, new AlbumComparator());
}
if (artists.size() > 0) {
Collections.sort(artists, new ArtistComparator());
Collections.sort(finalArtists, new ArtistComparator());
}
} catch (Exception e) {
e.printStackTrace();
}
List<UnifiedTrack> tmp = new ArrayList<>();
boolean queueCurrentIndexCollision = false;
int indexCorrection = 0;
for (int i = 0; i < queue.getQueue().size(); i++) {
UnifiedTrack ut = queue.getQueue().get(i);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
if (i == queueCurrentIndex) {
queueCurrentIndexCollision = true;
} else if (i < queueCurrentIndex) {
indexCorrection++;
}
tmp.add(ut);
}
}
}
for (int i = 0; i < tmp.size(); i++) {
queue.getQueue().remove(tmp.get(i));
}
if (queueCurrentIndexCollision) {
if (queue.getQueue().size() > 0) {
queueCurrentIndex = 0;
} else {
queue = new Queue();
}
} else {
queueCurrentIndex -= indexCorrection;
}
tmp.clear();
for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
UnifiedTrack ut = recentlyPlayed.getRecentlyPlayed().get(i);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
tmp.add(ut);
}
}
}
for (int i = 0; i < tmp.size(); i++) {
recentlyPlayed.getRecentlyPlayed().remove(tmp.get(i));
}
List<UnifiedTrack> temp = new ArrayList<>();
List<Playlist> tmpPL = new ArrayList<>();
for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
Playlist pl = allPlaylists.getPlaylists().get(i);
for (int j = 0; j < pl.getSongList().size(); j++) {
UnifiedTrack ut = pl.getSongList().get(j);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
temp.add(ut);
}
}
}
for (int j = 0; j < temp.size(); j++) {
pl.getSongList().remove(temp.get(j));
}
temp.clear();
if (pl.getSongList().size() == 0) {
tmpPL.add(pl);
}
}
for (int i = 0; i < tmpPL.size(); i++) {
allPlaylists.getPlaylists().remove(tmpPL.get(i));
}
tmpPL.clear();
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class HomeActivity method onLocalTrackSelected.
public void onLocalTrackSelected(int position) {
isReloaded = false;
HideBottomFakeToolbar();
if (!queueCall) {
CommonUtils.hideKeyboard(this);
searchView.setQuery("", true);
searchView.setIconified(true);
new Thread(new CancelCall()).start();
// hideTabs();
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.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
flag = 1;
isFavourite = true;
break;
}
}
if (flag == 0) {
isFavourite = false;
}
playerFragment.localIsPlaying = true;
playerFragment.localTrack = localSelectedTrack;
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).commitAllowingStateLoss();
} else {
if (playerFragment.localTrack != null && playerFragment.localIsPlaying && localSelectedTrack.getTitle() == playerFragment.localTrack.getTitle()) {
} else {
int flag = 0;
for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
if (ut.getType() && ut.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
flag = 1;
isFavourite = true;
break;
}
}
if (flag == 0) {
isFavourite = false;
}
playerFragment.localIsPlaying = true;
playerFragment.localTrack = localSelectedTrack;
frag.refresh();
}
}
if (!isQueueVisible)
showPlayer();
} else {
PlayerFragment frag = playerFragment;
playerFragment.localIsPlaying = true;
playerFragment.localTrack = localSelectedTrack;
int flag = 0;
for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
if (ut.getType() && ut.getLocalTrack().getTitle().equals(localSelectedTrack.getTitle())) {
flag = 1;
isFavourite = true;
break;
}
}
if (flag == 0) {
isFavourite = false;
}
if (frag != null)
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(true, playerFragment.localTrack, null);
for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
if (recentlyPlayed.getRecentlyPlayed().get(i).getType() && recentlyPlayed.getRecentlyPlayed().get(i).getLocalTrack().getTitle().equals(track.getLocalTrack().getTitle())) {
recentlyPlayed.getRecentlyPlayed().remove(i);
// rAdapter.notifyItemRemoved(i);
break;
}
}
recentlyPlayed.getRecentlyPlayed().add(0, track);
if (recentlyPlayed.getRecentlyPlayed().size() == 51) {
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.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class PlayerFragment method onViewCreated.
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
imgLoader = new ImageLoader(getContext());
smallPlayer = (RelativeLayout) view.findViewById(R.id.smallPlayer);
snappyRecyclerView = (SnappyRecyclerView) view.findViewById(R.id.visualizer_recycler);
bufferingIndicator = (AVLoadingIndicatorView) view.findViewById(R.id.bufferingIndicator);
currTime = (TextView) view.findViewById(R.id.currTime);
totalTime = (TextView) view.findViewById(R.id.totalTime);
repeatController = (ImageView) view.findViewById(R.id.repeat_controller);
shuffleController = (ImageView) view.findViewById(R.id.shuffle_controller);
spToolbar = (RelativeLayout) view.findViewById(R.id.smallPlayer_AB);
overflowMenuAB = (ImageView) view.findViewById(R.id.menuIcon);
lyricsContainer = (RelativeLayout) view.findViewById(R.id.lyrics_container);
lyricsIcon = (ImageView) view.findViewById(R.id.lyrics_icon);
lyricsContent = (TextView) view.findViewById(R.id.lyrics_content);
lyricsLoadingIndicator = (AVLoadingIndicatorView) view.findViewById(R.id.lyrics_loading_indicator);
lyricsStatus = (TextView) view.findViewById(R.id.lyrics_status_text);
lyricsIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isLyricsVisisble) {
lyricsIcon.setAlpha(1.0f);
mVisualizerView.setVisibility(View.GONE);
lyricsContainer.setVisibility(View.VISIBLE);
lyricsLoadingIndicator.setVisibility(View.VISIBLE);
lyricsStatus.setText("Searching Lyrics");
lyricsStatus.setVisibility(View.VISIBLE);
if (currentLyrics == null) {
downloadThread = new DownloadThread(PlayerFragment.this, false, selected_track_artist.getText().toString(), selected_track_title.getText().toString());
downloadThread.start();
} else {
onLyricsDownloaded(currentLyrics);
}
} else {
lyricsIcon.setAlpha(0.5f);
lyricsContent.setText("");
lyricsContainer.setVisibility(View.GONE);
mVisualizerView.setVisibility(View.VISIBLE);
}
isLyricsVisisble = !isLyricsVisisble;
}
});
spImgAB = (ImageView) view.findViewById(R.id.selected_track_image_sp_AB);
spImgAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!homeActivity.isPlayerTransitioning && smallPlayer != null) {
homeActivity.hidePlayer();
homeActivity.isPlayerVisible = false;
}
}
});
spTitleAB = (TextView) view.findViewById(R.id.selected_track_title_sp_AB);
spTitleAB.setSelected(true);
spArtistAB = (TextView) view.findViewById(R.id.selected_track_artist_sp_AB);
if (homeActivity.shuffleEnabled) {
shuffleController.setImageResource(R.drawable.ic_shuffle_filled);
} else {
shuffleController.setImageResource(R.drawable.ic_shuffle_alpha);
}
if (homeActivity.repeatEnabled) {
repeatController.setImageResource(R.drawable.ic_repeat_filled);
} else if (homeActivity.repeatOnceEnabled) {
repeatController.setImageResource(R.drawable.ic_repeat_once);
} else {
repeatController.setImageResource(R.drawable.ic_repeat_alpha);
}
repeatController.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (homeActivity.repeatOnceEnabled) {
homeActivity.repeatOnceEnabled = false;
repeatController.setImageResource(R.drawable.ic_repeat_alpha);
} else if (homeActivity.repeatEnabled) {
homeActivity.repeatEnabled = false;
homeActivity.repeatOnceEnabled = true;
repeatController.setImageResource(R.drawable.ic_repeat_once);
} else {
homeActivity.repeatEnabled = true;
repeatController.setImageResource(R.drawable.ic_repeat_filled);
}
}
});
shuffleController.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (homeActivity.shuffleEnabled) {
homeActivity.shuffleEnabled = false;
shuffleController.setImageResource(R.drawable.ic_shuffle_alpha);
mCallback.onShuffleDisabled();
} else {
homeActivity.shuffleEnabled = true;
shuffleController.setImageResource(R.drawable.ic_shuffle_filled);
mCallback.onShuffleEnabled();
}
snappyRecyclerView.scrollToPosition(HomeActivity.queueCurrentIndex);
snappyRecyclerView.setCurrentPosition(HomeActivity.queueCurrentIndex);
customAdapter.notifyDataSetChanged();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
snappyRecyclerView.setTransparency();
}
}, 400);
}
});
equalizerIcon = (ImageView) view.findViewById(R.id.equalizer_icon);
equalizerIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onEqualizerClicked();
}
});
equalizerIcon.setVisibility(View.INVISIBLE);
saveDNAToggle = (ImageView) view.findViewById(R.id.toggleSaveDNA);
if (homeActivity.isSaveDNAEnabled) {
saveDNAToggle.setImageResource(R.drawable.ic_save_filled);
} else {
saveDNAToggle.setImageResource(R.drawable.ic_save_alpha);
}
saveDNAToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (homeActivity.isSaveDNAEnabled) {
homeActivity.isSaveDNAEnabled = false;
saveDNAToggle.setImageResource(R.drawable.ic_save_alpha);
} else {
homeActivity.isSaveDNAEnabled = true;
saveDNAToggle.setImageResource(R.drawable.ic_save_filled);
}
}
});
mainTrackController = (ImageView) view.findViewById(R.id.controller);
nextTrackController = (ImageView) view.findViewById(R.id.next);
previousTrackController = (ImageView) view.findViewById(R.id.previous);
isFav = false;
favouriteIcon = (ImageView) view.findViewById(R.id.fav_icon);
favControllerSp = (ImageView) view.findViewById(R.id.fav_controller_sp);
if (homeActivity.isFavourite) {
favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
isFav = true;
} else {
favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
isFav = false;
}
favouriteIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFav) {
favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
isFav = false;
removeFromFavourite();
} else {
favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
isFav = true;
addToFavourite();
}
new HomeActivity.SaveFavourites().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
favControllerSp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFav) {
favouriteIcon.setImageResource(R.drawable.ic_heart_alpha);
favControllerSp.setImageResource(R.drawable.ic_heart_alpha);
isFav = false;
removeFromFavourite();
} else {
favouriteIcon.setImageResource(R.drawable.ic_heart_filled_1);
favControllerSp.setImageResource(R.drawable.ic_heart_filled_1);
isFav = true;
addToFavourite();
}
new HomeActivity.SaveFavourites().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
queueIcon = (ImageView) view.findViewById(R.id.queue_icon);
queueIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onQueueClicked();
}
});
selected_track_image = (ImageView) view.findViewById(R.id.selected_track_image_sp);
selected_track_title = (TextView) view.findViewById(R.id.selected_track_title_sp);
selected_track_artist = (TextView) view.findViewById(R.id.selected_track_artist_sp);
player_controller = (ImageView) view.findViewById(R.id.player_control_sp);
nextControllerSp = (ImageView) view.findViewById(R.id.next_controller_sp);
nextControllerSp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMediaPlayer.pause();
homeActivity.nextControllerClicked = true;
mCallback.onComplete();
}
});
bottomContainer = (RelativeLayout) view.findViewById(R.id.mainControllerContainer);
seekBarContainer = (RelativeLayout) view.findViewById(R.id.seekBarContainer);
toggleContainer = (RelativeLayout) view.findViewById(R.id.toggleContainer);
mVisualizerView = (VisualizerView) view.findViewById(R.id.myvisualizerview);
VisualizerView.w = HomeActivity.screen_width;
VisualizerView.h = HomeActivity.screen_height;
VisualizerView.conf = Bitmap.Config.ARGB_8888;
VisualizerView.bmp = Bitmap.createBitmap(VisualizerView.w, VisualizerView.h, VisualizerView.conf);
HomeActivity.cacheCanvas = new Canvas(VisualizerView.bmp);
if (HomeActivity.queue != null) {
customAdapter = new CustomAdapter(getContext(), snappyRecyclerView, HomeActivity.queue.getQueue());
} else {
customAdapter = new CustomAdapter(getContext(), snappyRecyclerView, new ArrayList<UnifiedTrack>());
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
snappyRecyclerView.setLayoutManager(linearLayoutManager);
snappyRecyclerView.setItemAnimator(new DefaultItemAnimator());
snappyRecyclerView.setAdapter(customAdapter);
snappyRecyclerView.setActivity(homeActivity);
snappyRecyclerView.addOnItemTouchListener(new ClickItemTouchListener(snappyRecyclerView) {
@Override
public boolean onClick(RecyclerView parent, View view, int position, long id) {
return false;
}
@Override
public boolean onLongClick(RecyclerView parent, View view, int position, long id) {
if (homeActivity.isFullScreenEnabled) {
homeActivity.isFullScreenEnabled = false;
bottomContainer.setVisibility(View.VISIBLE);
seekBarContainer.setVisibility(View.VISIBLE);
toggleContainer.setVisibility(View.VISIBLE);
spToolbar.setVisibility(View.VISIBLE);
mCallback.onFullScreen();
} else {
homeActivity.isFullScreenEnabled = true;
bottomContainer.setVisibility(View.GONE);
seekBarContainer.setVisibility(View.GONE);
toggleContainer.setVisibility(View.GONE);
spToolbar.setVisibility(View.INVISIBLE);
mCallback.onFullScreen();
}
return true;
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
cpb = (CustomProgressBar) view.findViewById(R.id.customProgress);
smallPlayer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onSmallPlayerTouched();
}
});
track = homeActivity.selectedTrack;
localTrack = homeActivity.localSelectedTrack;
if (homeActivity.streamSelected) {
try {
durationInMilliSec = track.getDuration();
} catch (Exception e) {
}
if (track.getArtworkURL() != null) {
Picasso.with(getActivity()).load(track.getArtworkURL()).resize(100, 100).into(selected_track_image);
} else {
selected_track_image.setImageResource(R.drawable.ic_default);
}
try {
spTitleAB.setText(track.getTitle());
selected_track_title.setText(track.getTitle());
selected_track_artist.setText("");
spArtistAB.setText("");
} catch (Exception e) {
}
} else {
try {
durationInMilliSec = (int) localTrack.getDuration();
} catch (Exception e) {
}
try {
imgLoader.DisplayImage(localTrack.getPath(), selected_track_image);
} catch (Exception e) {
}
try {
spTitleAB.setText(localTrack.getTitle());
selected_track_title.setText(localTrack.getTitle());
selected_track_artist.setText(localTrack.getArtist());
spArtistAB.setText(localTrack.getArtist());
} catch (Exception e) {
}
}
temp = getTime(durationInMilliSec);
totalTime.setText(temp.first + ":" + temp.second);
homeActivity.mWifi = homeActivity.connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
try {
if (homeActivity.streamSelected) {
if ((homeActivity.settings.isStreamOnlyOnWifiEnabled() && homeActivity.mWifi.isConnected()) || !homeActivity.settings.isStreamOnlyOnWifiEnabled()) {
isPrepared = false;
mMediaPlayer.reset();
mMediaPlayer.setDataSource(track.getStreamURL() + "?client_id=" + Config.CLIENT_ID);
mMediaPlayer.prepareAsync();
} else {
mMediaPlayer.pause();
homeActivity.nextControllerClicked = true;
mCallback.onComplete();
}
} else {
isPrepared = false;
mMediaPlayer.reset();
File f = new File(localTrack.getPath());
if (f.exists()) {
mMediaPlayer.setDataSource(localTrack.getPath());
mMediaPlayer.prepareAsync();
} else {
Toast.makeText(getContext(), "Error playing " + localTrack.getTitle() + ". Skipping to next track", Toast.LENGTH_SHORT).show();
mMediaPlayer.pause();
homeActivity.nextControllerClicked = true;
mCallback.onComplete();
}
}
bufferingIndicator.setVisibility(View.VISIBLE);
mainTrackController.setVisibility(View.GONE);
} catch (Exception e) {
e.printStackTrace();
}
overflowMenuAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popMenu = new PopupMenu(getContext(), overflowMenuAB);
popMenu.getMenuInflater().inflate(R.menu.player_overflow_menu, popMenu.getMenu());
popMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getTitle().equals("Full Screen")) {
if (homeActivity.isFullScreenEnabled) {
homeActivity.isFullScreenEnabled = false;
bottomContainer.setVisibility(View.VISIBLE);
seekBarContainer.setVisibility(View.VISIBLE);
toggleContainer.setVisibility(View.VISIBLE);
spToolbar.setVisibility(View.VISIBLE);
mCallback.onFullScreen();
} else {
homeActivity.isFullScreenEnabled = true;
bottomContainer.setVisibility(View.GONE);
seekBarContainer.setVisibility(View.GONE);
toggleContainer.setVisibility(View.GONE);
spToolbar.setVisibility(View.INVISIBLE);
mCallback.onFullScreen();
}
} else if (item.getTitle().equals("Settings")) {
mCallback.onSettingsClicked();
} else if (item.getTitle().equals("Add to playlist")) {
UnifiedTrack ut = HomeActivity.queue.getQueue().get(HomeActivity.queueCurrentIndex);
mCallback.addCurrentSongtoPlaylist(ut);
}
return true;
}
});
popMenu.show();
}
});
player_controller.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isReplayIconVisible) {
homeActivity.hasQueueEnded = true;
mCallback.onComplete();
} else {
if (!pauseClicked) {
pauseClicked = true;
}
togglePlayPause();
}
}
});
mainTrackController.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isReplayIconVisible) {
homeActivity.hasQueueEnded = true;
mCallback.onComplete();
} else {
if (!pauseClicked) {
pauseClicked = true;
}
togglePlayPause();
}
}
});
nextTrackController.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMediaPlayer.pause();
homeActivity.nextControllerClicked = true;
mCallback.onComplete();
}
});
previousTrackController.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (homeActivity.queueCurrentIndex != 0) {
mMediaPlayer.pause();
mCallback.onPreviousTrack();
}
}
});
progressBar = (SeekBar) view.findViewById(R.id.progressBar);
progressBar.setMax(durationInMilliSec);
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (isPrepared && !isTracking && getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
float[] hsv = new float[3];
hsv[0] = homeActivity.seekBarColor;
hsv[1] = (float) 0.8;
hsv[2] = (float) 0.5;
progressBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(Color.HSVToColor(hsv), PorterDuff.Mode.SRC_IN));
cpb.update();
}
});
try {
temp = getTime(mMediaPlayer.getCurrentPosition());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
currTime.setText(temp.first + ":" + temp.second);
}
});
progressBar.setProgress(mMediaPlayer.getCurrentPosition());
} catch (Exception e) {
Log.e("MEDIA", e.getMessage() + ":");
}
}
}
}, 0, 50);
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
temp = getTime(progress);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
currTime.setText(temp.first + ":" + temp.second);
}
});
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
isTracking = true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mMediaPlayer.seekTo(seekBar.getProgress());
if (mMediaPlayer.isPlaying())
mMediaPlayer.start();
isTracking = false;
}
});
final Button mEndButton = new Button(getContext());
mEndButton.setBackgroundColor(homeActivity.themeColor);
mEndButton.setTextColor(Color.WHITE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
showCase = new ShowcaseView.Builder(getActivity()).blockAllTouches().singleShot(2).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(homeActivity.tp).setTarget(new ViewTarget(mVisualizerView.getId(), getActivity())).setContentTitle("The DNA").setContentText("The DNA of the currently playing song.").build();
showCase.setButtonText("Next");
showCase.setButtonPosition(homeActivity.lps);
showCase.overrideButtonClick(new View.OnClickListener() {
int count1 = -1;
@Override
public void onClick(View v) {
count1++;
switch(count1) {
case 0:
showCase.setTarget(new ViewTarget(mVisualizerView.getId(), getActivity()));
showCase.setContentTitle("The DNA");
showCase.setContentText("Swipe Left or Right to change Song." + "Long Press for fullscreen");
showCase.setButtonPosition(homeActivity.lps);
showCase.setButtonText("Next");
break;
case 1:
showCase.setTarget(new ViewTarget(R.id.toggleContainer, getActivity()));
showCase.setContentTitle("The Controls");
showCase.setContentText("Equalizer \n" + "Save DNA toggle\n" + "Add to Favourites \n" + "Queue");
showCase.setButtonPosition(homeActivity.lps);
showCase.setButtonText("Done");
break;
case 2:
showCase.setTarget(new ViewTarget(R.id.lyrics_icon, getActivity()));
showCase.setContentTitle("Lyrics");
showCase.setContentText("Get lyrics by tapping this icon");
showCase.setButtonPosition(homeActivity.lps);
showCase.setButtonText("Done");
break;
case 3:
showCase.hide();
break;
}
}
});
}
}, 500);
}
use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.
the class QueueRecyclerAdapter method onItemDismiss.
@Override
public void onItemDismiss(int position) {
UnifiedTrack ut = queue.get(position);
if (HomeActivity.originalQueue != null)
HomeActivity.originalQueue.removeItem(ut);
queue.remove(position);
if (position < HomeActivity.queueCurrentIndex) {
HomeActivity.queueCurrentIndex--;
}
notifyItemRemoved(position);
((HomeActivity) ctx).updateVisualizerRecycler();
new HomeActivity.SaveQueue().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations