mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Get correct stream uri for downloaded content
This commit is contained in:
parent
f416bfda8f
commit
827dd7d2ae
3 changed files with 59 additions and 19 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.cappielloantonio.play.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ComponentName;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
|
@ -13,6 +15,8 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.media3.session.SessionToken;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.PagerSnapHelper;
|
||||
import androidx.recyclerview.widget.SnapHelper;
|
||||
|
|
@ -29,9 +33,11 @@ import com.cappielloantonio.play.model.Album;
|
|||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.service.MediaService;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.UIUtil;
|
||||
import com.cappielloantonio.play.viewmodel.DownloadViewModel;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -47,6 +53,8 @@ public class DownloadFragment extends Fragment {
|
|||
private SongHorizontalAdapter downloadedTrackAdapter;
|
||||
private PlaylistAdapter playlistAdapter;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -88,10 +96,25 @@ public class DownloadFragment extends Fragment {
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
initializeMediaBrowser();
|
||||
activity.setBottomNavigationBarVisibility(true);
|
||||
activity.setBottomSheetVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
setMediaBrowserListenableFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
releaseMediaBrowser();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
|
@ -285,4 +308,17 @@ public class DownloadFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void initializeMediaBrowser() {
|
||||
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
|
||||
}
|
||||
|
||||
private void releaseMediaBrowser() {
|
||||
MediaBrowser.releaseFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
private void setMediaBrowserListenableFuture() {
|
||||
downloadedTrackAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,16 +153,6 @@ public class HomeFragment extends Fragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void initializeMediaBrowser() {
|
||||
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
|
||||
}
|
||||
|
||||
private void releaseMediaBrowser() {
|
||||
MediaBrowser.releaseFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
bind.recentlyAddedAlbumsTextViewClickable.setOnClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
|
|
@ -246,12 +236,6 @@ public class HomeFragment extends Fragment {
|
|||
Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null));
|
||||
}
|
||||
|
||||
private void setMediaBrowserListenableFuture() {
|
||||
discoverSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
similarMusicAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
starredSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
private void initDiscoverSongSlideView() {
|
||||
bind.discoverSongViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
|
||||
|
||||
|
|
@ -541,6 +525,7 @@ public class HomeFragment extends Fragment {
|
|||
genericPlaylistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
SongHorizontalAdapter trackAdapter = new SongHorizontalAdapter(activity, requireContext(), true);
|
||||
trackAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
genericPlaylistRecyclerView.setAdapter(trackAdapter);
|
||||
|
||||
homeViewModel.getPlaylistSongLiveList(playlist.getId()).observe(requireActivity(), songs -> {
|
||||
|
|
@ -578,4 +563,19 @@ public class HomeFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void initializeMediaBrowser() {
|
||||
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
|
||||
}
|
||||
|
||||
private void releaseMediaBrowser() {
|
||||
MediaBrowser.releaseFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
private void setMediaBrowserListenableFuture() {
|
||||
discoverSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
similarMusicAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
starredSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,13 @@ public class MusicUtil {
|
|||
"&t=" + params.get("t") +
|
||||
"&v=" + params.get("v") +
|
||||
"&c=" + params.get("c") +
|
||||
"&id=" + song.getId() +
|
||||
"&maxBitRate=" + getBitratePreference(context, connectivityManager.getActiveNetworkInfo().getType()) +
|
||||
"&format=" + getTranscodingFormatPreference(context, connectivityManager.getActiveNetworkInfo().getType());
|
||||
"&id=" + song.getId();
|
||||
|
||||
if(connectivityManager.getActiveNetworkInfo() != null) {
|
||||
uri = uri + "&maxBitRate="
|
||||
+ getBitratePreference(context, connectivityManager.getActiveNetworkInfo().getType()) + "&format="
|
||||
+ getTranscodingFormatPreference(context, connectivityManager.getActiveNetworkInfo().getType());
|
||||
}
|
||||
|
||||
Log.d(TAG, "getSongStreamUri(): " + uri);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue