首页数据根据pageType区分页面类型,专辑列表或者视频

This commit is contained in:
litingting 2024-10-12 18:39:45 +08:00
parent b67911fde7
commit 58e1bd0804
19 changed files with 432 additions and 136 deletions

View File

@ -20,6 +20,7 @@ import com.hi.music.player.MusicApplication;
import com.hi.music.player.R; import com.hi.music.player.R;
import com.hi.music.player.databinding.ItemCategoryBinding; import com.hi.music.player.databinding.ItemCategoryBinding;
import com.hi.music.player.helper.CommonUtils; import com.hi.music.player.helper.CommonUtils;
import com.hi.music.player.helper.MyValue;
import com.hi.music.player.javabean.response.child.ResponseCategory; import com.hi.music.player.javabean.response.child.ResponseCategory;
public class AdapterCategory extends BaseAdapter<ResponseCategory, ItemCategoryBinding>{ public class AdapterCategory extends BaseAdapter<ResponseCategory, ItemCategoryBinding>{
@ -37,6 +38,18 @@ public class AdapterCategory extends BaseAdapter<ResponseCategory, ItemCategoryB
VHolder<ItemCategoryBinding> itemHolder = (VHolder<ItemCategoryBinding>) holder; VHolder<ItemCategoryBinding> itemHolder = (VHolder<ItemCategoryBinding>) holder;
ItemCategoryBinding vb = itemHolder.getVb(); ItemCategoryBinding vb = itemHolder.getVb();
ResponseCategory responseCategory = data.get(position); ResponseCategory responseCategory = data.get(position);
String pageType = responseCategory.getPageType();
if(pageType.equals(MyValue.PAGE_TYPE_MV)){
ViewGroup.LayoutParams layoutParams = vb.header.getLayoutParams();
layoutParams.width = CommonUtils.dpToPx(260);
vb.header.setLayoutParams(layoutParams);
}else {
ViewGroup.LayoutParams layoutParams = vb.header.getLayoutParams();
layoutParams.width = CommonUtils.dpToPx(170);
vb.header.setLayoutParams(layoutParams);
}
Glide.with(MusicApplication.myApplication) Glide.with(MusicApplication.myApplication)
.asDrawable() .asDrawable()

View File

@ -44,25 +44,36 @@ public class AdapterCategoryList extends BaseAdapter<ResponsePlayListInfo, ItemC
vb.tvSongName.setText(child.getSongTitle()); vb.tvSongName.setText(child.getSongTitle());
vb.tvSingerName.setText(child.getSingerName()); vb.tvSingerName.setText(child.getSingerName());
Glide.with(MusicApplication.myApplication)
.asDrawable()
.apply(RequestOptions.bitmapTransform(new RoundedCorners(CommonUtils.dpToPx(16))))
.load(child.getCovert())
.placeholder(R.mipmap.ic_launcher)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target<Drawable> target, boolean isFirstResource) {
CommonUtils.LogMsg(e.getMessage());
return false;
}
@OptIn(markerClass = UnstableApi.class) String smallCovert = child.getSmallCovert();
@Override if(smallCovert == null){
public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target<Drawable> target, @NonNull DataSource dataSource, boolean isFirstResource) { vb.image.setVisibility(View.GONE);
return false; vb.tvPosition.setVisibility(View.VISIBLE);
} vb.tvPosition.setText(position);
}) }else {
.into(vb.image); vb.image.setVisibility(View.VISIBLE);
vb.tvPosition.setVisibility(View.GONE);
Glide.with(MusicApplication.myApplication)
.asDrawable()
.apply(RequestOptions.bitmapTransform(new RoundedCorners(CommonUtils.dpToPx(16))))
.load(child.getSmallCovert())
.placeholder(R.mipmap.ic_launcher)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target<Drawable> target, boolean isFirstResource) {
CommonUtils.LogMsg(e.getMessage());
return false;
}
@OptIn(markerClass = UnstableApi.class)
@Override
public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target<Drawable> target, @NonNull DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(vb.image);
}
vb.getRoot().setOnClickListener(new View.OnClickListener() { vb.getRoot().setOnClickListener(new View.OnClickListener() {
@Override @Override

View File

@ -1,8 +1,12 @@
package com.hi.music.player.api; package com.hi.music.player.api;
public interface RequestListener<T> { import org.json.JSONObject;
import okhttp3.ResponseBody;
public interface RequestListener<T> {
void onFail(String errorMsg); void onFail(String errorMsg);
void onSuccess(T data) ; void onSuccess(JSONObject data) ;
} }

View File

@ -1,13 +1,40 @@
package com.hi.music.player.helper; package com.hi.music.player.helper;
public class MyValue { public class MyValue {
public static String PAGE_TYPE_MV="MUSIC_PAGE_TYPE_ARTIST";
public static String PAGE_TYPE_LIST="MUSIC_PAGE_TYPE_PLAYLIST";
public static String PAGE_TYPE_ALBUM="MUSIC_PAGE_TYPE_ALBUM";
//-----------------------------PlayActivity //-----------------------------PlayActivity
/**
* 歌手单曲进入的数据key
*/
public static String KEY_PLAY_ACTIVITY_SINGER = "click_singer"; public static String KEY_PLAY_ACTIVITY_SINGER = "click_singer";
/**
* 音乐列表进入的数据key和点击的列表位置key
*/
public static String KEY_PLAY_ACTIVITY_CATEGORY_LIST = "click_category_list"; public static String KEY_PLAY_ACTIVITY_CATEGORY_LIST = "click_category_list";
public static String KEY_PLAY_ACTIVITY_CATEGORY_LIST_INDEX = "click_category_list_index"; public static String KEY_PLAY_ACTIVITY_CATEGORY_LIST_INDEX = "click_category_list_index";
/**
* MV进入的数据key
*/
public static String KEY_PLAY_ACTIVITY_MV = "click_mv";
//播放错误 //播放错误
public final static int PLAY_STATUS_CODE_ERROR = -1; public final static int PLAY_STATUS_CODE_ERROR = -1;
@ -23,15 +50,16 @@ public class MyValue {
/** /**
* 进入播放页面的来源 * 进入播放页面的来源
* 0--单曲进入 0--单曲进入 0--音乐分类合集列表进入 * 0--单曲进入 1--音乐分类合集列表进入 2--视频mv进入
*/ */
public static String KEY_ENTER_SOURCE = "ENTER_SOURCE"; public static String KEY_ENTER_SOURCE = "ENTER_SOURCE";
public final static int TYPE_ENTER_SOURCE_SINGLE = 0; public final static int TYPE_ENTER_SOURCE_SINGLE = 0;
public final static int TYPE_ENTER_SOURCE_CATEGORY = 1; public final static int TYPE_ENTER_SOURCE_CATEGORY = 1;
public final static int TYPE_ENTER_SOURCE_MV = 2;
//-----------------------------PlayActivity //-----------------------------PlayActivity

View File

@ -15,6 +15,66 @@ public class ResponseCategory implements Serializable {
private String browseId; private String browseId;
private String videoId;
private String playListId;
private String params;
private String musicVideoType;
/**
* 视频Mv
*MUSIC_PAGE_TYPE_USER_CHANNEL
*
* 音乐合集列表
* MUSIC_PAGE_TYPE_PLAYLIST
*
* 专辑
*MUSIC_PAGE_TYPE_ALBUM
*/
private String pageType;
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public String getMusicVideoType() {
return musicVideoType;
}
public void setMusicVideoType(String musicVideoType) {
this.musicVideoType = musicVideoType;
}
public String getPlayListId() {
return playListId;
}
public void setPlayListId(String playListId) {
this.playListId = playListId;
}
public String getVideoId() {
return videoId;
}
public void setVideoId(String videoId) {
this.videoId = videoId;
}
public String getPageType() {
return pageType;
}
public void setPageType(String pageType) {
this.pageType = pageType;
}
public String getBrowseId() { public String getBrowseId() {
return browseId; return browseId;

View File

@ -1,6 +1,7 @@
package com.hi.music.player.network; package com.hi.music.player.network;
import com.hi.music.player.helper.CommonUtils; import com.hi.music.player.helper.CommonUtils;
import com.hi.music.player.helper.MyValue;
import com.hi.music.player.javabean.response.ResponseCategoryList; import com.hi.music.player.javabean.response.ResponseCategoryList;
import com.hi.music.player.javabean.response.ResponsePlayListInfo; import com.hi.music.player.javabean.response.ResponsePlayListInfo;
import com.hi.music.player.javabean.response.ResponsePlayUrl; import com.hi.music.player.javabean.response.ResponsePlayUrl;
@ -42,7 +43,7 @@ public class JsonHelper {
} catch (JSONException exception) { } catch (JSONException exception) {
CommonUtils.LogMsg("----------exception="); CommonUtils.LogMsg("---------首页-exception=");
exception.printStackTrace(); exception.printStackTrace();
} }
@ -216,73 +217,72 @@ public class JsonHelper {
//轻松愉悦的经典摇滚乐 //轻松愉悦的经典摇滚乐
String title = getJsonTitle(musicResponsiveHeaderRenderer.getJSONObject("title"), 0); String title = getJsonTitle(musicResponsiveHeaderRenderer.getJSONObject("title"), 0);
//Hold on to the feeling. String description = "";
String description = getJsonTitle(musicResponsiveHeaderRenderer.getJSONObject("description")
.getJSONObject("musicDescriptionShelfRenderer")
.getJSONObject("description"), 0);
//110 首歌曲.超过6小时 //110 首歌曲.超过6小时
String secondSubtitle = getJsonTextNew(musicResponsiveHeaderRenderer.getJSONObject("secondSubtitle")); String secondSubtitle = getJsonTextNew(musicResponsiveHeaderRenderer.getJSONObject("secondSubtitle"));
CommonUtils.LogMsg("-------------title="+title+"--description="+description+"---secondSubtitle="+secondSubtitle+"---covert="+covert); if(musicResponsiveHeaderRenderer.has("description")){
//-----------------单曲合集类型
//Hold on to the feeling.
description = getJsonTitle(musicResponsiveHeaderRenderer.getJSONObject("description")
.getJSONObject("musicDescriptionShelfRenderer")
.getJSONObject("description"), 0);
}
if(musicResponsiveHeaderRenderer.has("subtitle")){
//-----------------专辑类型
//专辑.1998
description = getJsonTextNew(musicResponsiveHeaderRenderer.getJSONObject("subtitle"));
}
JSONArray jsonArray = jsonObject1.getJSONObject("secondaryContents")
.getJSONObject("sectionListRenderer")
.getJSONArray("contents")
.getJSONObject(0)
.getJSONObject("musicPlaylistShelfRenderer")
.getJSONArray("contents");
responseCategoryList.setCovert(covert); responseCategoryList.setCovert(covert);
responseCategoryList.setDescription(description); responseCategoryList.setDescription(description);
responseCategoryList.setTitle(title); responseCategoryList.setTitle(title);
responseCategoryList.setSecondSubtitle(secondSubtitle); responseCategoryList.setSecondSubtitle(secondSubtitle);
CommonUtils.LogMsg("-------------title="+title+"--description="+description+"---secondSubtitle="+secondSubtitle+"---covert="+covert);
JSONObject contentsArray = jsonObject1.getJSONObject("secondaryContents")
.getJSONObject("sectionListRenderer")
.getJSONArray("contents")
.getJSONObject(0);
List<ResponsePlayListInfo> mList = new ArrayList<>(); List<ResponsePlayListInfo> mList = new ArrayList<>();
for(int i = 0;i<jsonArray.length();i++){ if(contentsArray.has("musicPlaylistShelfRenderer")){
JSONObject arrayJSONObject = jsonArray.getJSONObject(i).getJSONObject("musicResponsiveListItemRenderer"); //分类音乐合集的播放列表
JSONArray jsonArray = contentsArray.getJSONObject("musicPlaylistShelfRenderer")
.getJSONArray("contents");
String duration = getJsonTitle(arrayJSONObject.getJSONArray("fixedColumns").getJSONObject(0).getJSONObject("musicResponsiveListItemFixedColumnRenderer").getJSONObject("text"), 0);
long ms = CommonUtils.convertToMilliseconds(duration);
String thumbnail = getCovertUrl(arrayJSONObject.getJSONObject("thumbnail"), true);
JSONArray flexColumns = arrayJSONObject for(int i = 0;i<jsonArray.length();i++){
.getJSONArray("flexColumns"); JSONObject arrayJSONObject = jsonArray.getJSONObject(i).getJSONObject("musicResponsiveListItemRenderer");
ResponsePlayListInfo child = getCommonCategoryList(arrayJSONObject);
String thumbnail = getCovertUrl(arrayJSONObject.getJSONObject("thumbnail"), true);
ResponsePlayListInfo child = new ResponsePlayListInfo(); child.setSmallCovert(thumbnail);
//歌名歌手名字描述 // child.setCovert(thumbnail);
String SongTitle = ""; mList.add(child);
String SingerName = "";
String Description = "";
for (int g = 0; g < flexColumns.length(); g++) {
JSONObject jsonObjectText = flexColumns.getJSONObject(g).getJSONObject("musicResponsiveListItemFlexColumnRenderer").getJSONObject("text");
String text = getJsonTitle(jsonObjectText, 0);
if (g == 0) {
SongTitle = text;
JSONObject runs = jsonObjectText.getJSONArray("runs").getJSONObject(0); CommonUtils.LogMsg("--歌曲"+i+"-------------SongTitle="+child.getSongTitle()+"--getVideoId="+child.getVideoId());
}
}
String[] watchEndPoint = getWatchEndPoint(runs); if(contentsArray.has("musicShelfRenderer")){
// 专辑音乐的播放列表
JSONArray jsonArray = contentsArray.getJSONObject("musicShelfRenderer")
.getJSONArray("contents");
for(int i = 0;i<jsonArray.length();i++){
JSONObject arrayJSONObject = jsonArray.getJSONObject(i).getJSONObject("musicResponsiveListItemRenderer");
ResponsePlayListInfo child = getCommonCategoryList(arrayJSONObject);
child.setCovert(covert);
child.setVideoId(watchEndPoint[0]); mList.add(child);
child.setPlaylistId(watchEndPoint[1]);
child.setParams(watchEndPoint[2]);
child.setMusicVideoType(watchEndPoint[3]);
}
if (g == 1) SingerName = text;
if (g == 2) Description = text;
} }
child.setSmallCovert(thumbnail);
// child.setCovert(thumbnail);
child.setDuration(duration);
child.setDurationMs(ms);
child.setSingerName(SingerName);
child.setSongTitle(SongTitle);
mList.add(child);
CommonUtils.LogMsg("--歌曲"+i+"-------------SongTitle="+SongTitle+"--SingerName="+SingerName+"---Description="+Description+"---duration="+duration+"--thumbnail="+thumbnail);
} }
responseCategoryList.setList(mList); responseCategoryList.setList(mList);
return responseCategoryList; return responseCategoryList;
@ -308,6 +308,45 @@ public class JsonHelper {
private static ResponsePlayListInfo getCommonCategoryList(JSONObject musicResponsiveListItemRenderer) throws JSONException {
String duration = getJsonTitle(musicResponsiveListItemRenderer.getJSONArray("fixedColumns").getJSONObject(0).getJSONObject("musicResponsiveListItemFixedColumnRenderer").getJSONObject("text"), 0);
long ms = CommonUtils.convertToMilliseconds(duration);
JSONArray flexColumns = musicResponsiveListItemRenderer
.getJSONArray("flexColumns");
ResponsePlayListInfo listInfo = new ResponsePlayListInfo();
//歌名歌手名字描述
String SongTitle = "";
String SingerName = "";
String Description = "";
for (int g = 0; g < flexColumns.length(); g++) {
JSONObject jsonObjectText = flexColumns.getJSONObject(g).getJSONObject("musicResponsiveListItemFlexColumnRenderer").getJSONObject("text");
String text = getJsonTitle(jsonObjectText, 0);
if (g == 0) {
SongTitle = text;
JSONObject runs = jsonObjectText.getJSONArray("runs").getJSONObject(0);
String[] watchEndPoint = getWatchEndPoint(runs);
listInfo.setVideoId(watchEndPoint[0]);
listInfo.setPlaylistId(watchEndPoint[1]);
listInfo.setParams(watchEndPoint[2]);
listInfo.setMusicVideoType(watchEndPoint[3]);
}
if (g == 1) SingerName = text;
if (g == 2) Description = text;
}
listInfo.setDuration(duration);
listInfo.setDurationMs(ms);
listInfo.setSingerName(SingerName);
listInfo.setSongTitle(SongTitle);
return listInfo;
}
private static void getCommonHome(JSONObject sectionListRenderer, ResponseHome responseHome) throws JSONException { private static void getCommonHome(JSONObject sectionListRenderer, ResponseHome responseHome) throws JSONException {
@ -317,8 +356,8 @@ public class JsonHelper {
String clickTrackingParams = nextContinuationData.getString("clickTrackingParams"); String clickTrackingParams = nextContinuationData.getString("clickTrackingParams");
String continuation = nextContinuationData.getString("continuation"); String continuation = nextContinuationData.getString("continuation");
CommonUtils.LogMsg("---------参数---clickTrackingParams=" + clickTrackingParams); // CommonUtils.LogMsg("---------参数---clickTrackingParams=" + clickTrackingParams);
CommonUtils.LogMsg("---------参数--continuation=" + continuation); // CommonUtils.LogMsg("---------参数--continuation=" + continuation);
responseHome.setClickTrackingParams(clickTrackingParams); responseHome.setClickTrackingParams(clickTrackingParams);
responseHome.setContinuation(continuation); responseHome.setContinuation(continuation);
@ -332,7 +371,7 @@ public class JsonHelper {
JSONObject musicCarouselShelfRenderer = object.optJSONObject("musicCarouselShelfRenderer"); JSONObject musicCarouselShelfRenderer = object.optJSONObject("musicCarouselShelfRenderer");
if (musicCarouselShelfRenderer != null) { if (musicCarouselShelfRenderer != null) {
//-------------------------单曲
//模块标题 //模块标题
String title = getJsonTitle(musicCarouselShelfRenderer.getJSONObject("header").getJSONObject("musicCarouselShelfBasicHeaderRenderer").getJSONObject("title"), 0); String title = getJsonTitle(musicCarouselShelfRenderer.getJSONObject("header").getJSONObject("musicCarouselShelfBasicHeaderRenderer").getJSONObject("title"), 0);
CommonUtils.LogMsg("----------headertitle=" + title); CommonUtils.LogMsg("----------headertitle=" + title);
@ -374,18 +413,24 @@ public class JsonHelper {
} }
if (g == 1) SingerName = text; if (g == 1) SingerName = text;
if (g == 2) Description = text; if (g == 2) {
//这里应该没有值
Description = text;
}
} }
responseSingle.setSongTitle(SongTitle); responseSingle.setSongTitle(SongTitle);
responseSingle.setSingerName(SingerName); responseSingle.setSingerName(SingerName);
responseSingle.setSingerHead(SingerHead); responseSingle.setSingerHead(SingerHead);
responseSingle.setDescription(Description); responseSingle.setDescription(Description);
singleList.add(responseSingle); singleList.add(responseSingle);
CommonUtils.LogMsg(" ----------111111111111----SongTitle=" + SongTitle + "--SingerName=" + SingerName + "---Description=" + Description + "--SingerHead=" + SingerHead);
//"musicVideoType":"MUSIC_VIDEO_TYPE_UGC"
// CommonUtils.LogMsg(" ----------111111111111----SongTitle=" + SongTitle + "--getMusicVideoType=" + responseSingle.getMusicVideoType() );
} }
JSONObject musicTwoRowItemRenderer = jsonList.optJSONObject("musicTwoRowItemRenderer"); JSONObject musicTwoRowItemRenderer = jsonList.optJSONObject("musicTwoRowItemRenderer");
if (musicTwoRowItemRenderer != null) { if (musicTwoRowItemRenderer != null) {
//------------------------音乐合集或者专辑
ResponseCategory responseCategory = new ResponseCategory(); ResponseCategory responseCategory = new ResponseCategory();
String covert = getCovertUrl(musicTwoRowItemRenderer.getJSONObject("thumbnailRenderer"), true); String covert = getCovertUrl(musicTwoRowItemRenderer.getJSONObject("thumbnailRenderer"), true);
@ -393,20 +438,82 @@ public class JsonHelper {
String twoTitle = getJsonTitle(title1, 0); String twoTitle = getJsonTitle(title1, 0);
String twoSubtitle = getJsonTextNew(musicTwoRowItemRenderer.getJSONObject("subtitle")); String twoSubtitle = getJsonTextNew(musicTwoRowItemRenderer.getJSONObject("subtitle"));
String browseId = title1
String browseId = "";
JSONObject runs = title1
.getJSONArray("runs") .getJSONArray("runs")
.getJSONObject(0) .getJSONObject(0);
.getJSONObject("navigationEndpoint") JSONObject subtitle = musicTwoRowItemRenderer
.getJSONObject("browseEndpoint") .getJSONObject("subtitle")
.getString("browseId"); .getJSONArray("runs")
.getJSONObject(0);
JSONObject browseEndpoint = null;
if(runs.has("navigationEndpoint")){
//-------------当pageType="MUSIC_PAGE_TYPE_PLAYLIST""MUSIC_PAGE_TYPE_ALBUM" 走这里
browseEndpoint = runs.getJSONObject("navigationEndpoint")
.getJSONObject("browseEndpoint");
CommonUtils.LogMsg(" ----------2222222222----twoTitle=" + twoTitle + "-browseId 111=" + browseId);
}
if(subtitle.has("navigationEndpoint")){
//-------------当pageType="MUSIC_PAGE_TYPE_ARTIST" 走这里
browseEndpoint = subtitle.getJSONObject("navigationEndpoint")
.getJSONObject("browseEndpoint");
CommonUtils.LogMsg(" ----------2222222222----twoTitle=" + twoTitle + "-browseId 222=" + browseId);
}
if(browseEndpoint!= null){
browseId = browseEndpoint
.getString("browseId");
String pageType = browseEndpoint.getJSONObject("browseEndpointContextSupportedConfigs")
.getJSONObject("browseEndpointContextMusicConfig")
.getString("pageType");
responseCategory.setPageType(pageType);
responseCategory.setBrowseId(browseId);
if(pageType.equals(MyValue.PAGE_TYPE_MV)){
//视频mv 需要获取videoId 和PlayListId 用于进入播放页面请求播放列表数据
JSONObject jsonObject = musicTwoRowItemRenderer.getJSONObject("menu")
.getJSONObject("menuRenderer")
.getJSONArray("items")
.getJSONObject(0)
.getJSONObject("menuNavigationItemRenderer");
String[] watchEndPoint = getWatchEndPoint(jsonObject);
if(watchEndPoint[0]!=null){
responseCategory.setVideoId(watchEndPoint[0]);
}
if(watchEndPoint[1]!=null){
responseCategory.setPlayListId(watchEndPoint[1]);
}
if(watchEndPoint[2]!=null) {
responseCategory.setParams(watchEndPoint[2]);
}
if(watchEndPoint[3]!=null) {
responseCategory.setMusicVideoType(watchEndPoint[3]);
}
CommonUtils.LogMsg("");
}
}
// if(musicTwoRowItemRenderer.has("navigationEndpoint")){
// String[] navigationEndpoints = getWatchEndPoint(musicTwoRowItemRenderer);
// if(navigationEndpoints[0]!=null){
// responseCategory.setVideoId(navigationEndpoints[0]);
// }
// if(navigationEndpoints[1]!=null){
// responseCategory.setPlayListId(navigationEndpoints[0]);
// }
// }
responseCategory.setBrowseId(browseId);
responseCategory.setCovert(covert); responseCategory.setCovert(covert);
responseCategory.setTwoTitle(twoTitle); responseCategory.setTwoTitle(twoTitle);
responseCategory.setTwoSubtitle(twoSubtitle); responseCategory.setTwoSubtitle(twoSubtitle);
categoryList.add(responseCategory); categoryList.add(responseCategory);
CommonUtils.LogMsg(" ----------2222222222----twoTitle=" + twoTitle + "-twoSubtitle=" + twoSubtitle); CommonUtils.LogMsg(" ----------2222222222----twoTitle=" + twoTitle + "-twoSubtitle="
+ twoSubtitle+"---pageType="+responseCategory.getPageType()
+"--VideoId="+responseCategory.getVideoId()
+"---PlayListId="+responseCategory.getPlayListId());
} }
} }
@ -488,7 +595,7 @@ public class JsonHelper {
} }
} catch (JSONException exception) { } catch (JSONException exception) {
exception.printStackTrace(); return text;
} }
return text; return text;
} }

View File

@ -55,7 +55,7 @@ public interface MusicApi {
//首页分类项下的播放列表子页面 //首页分类项下的播放列表子页面 (类型1单曲合集2专辑3音乐视频 不同类型返回数据结构有区别)
@POST("youtubei/v1/browse") @POST("youtubei/v1/browse")
@Headers("X-Goog-Api-Key:AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8") @Headers("X-Goog-Api-Key:AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8")
Observable<ResponseBody> getCategoryList(@Body RequestBody requestBody); Observable<ResponseBody> getCategoryList(@Body RequestBody requestBody);

View File

@ -3,8 +3,12 @@ package com.hi.music.player.network;
import com.hi.music.player.api.RequestListener; import com.hi.music.player.api.RequestListener;
import com.hi.music.player.helper.CommonUtils; import com.hi.music.player.helper.CommonUtils;
import org.json.JSONException;
import org.json.JSONObject;
import io.reactivex.Observer; import io.reactivex.Observer;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;
public class ObserverWrapper<T> implements Observer<T> { public class ObserverWrapper<T> implements Observer<T> {
private RequestListener<T> requestListener; private RequestListener<T> requestListener;
@ -20,13 +24,31 @@ public class ObserverWrapper<T> implements Observer<T> {
@Override @Override
public void onNext(T t) { public void onNext(T t) {
ResponseBody responseBody = (ResponseBody) t;
JSONObject jsonObject = CommonUtils.toJsonObject(responseBody);
try {
if (jsonObject != null) {
if (jsonObject.has("playabilityStatus")) {
String status = jsonObject.getJSONObject("playabilityStatus").getString("status");
if (!status.equals("OK")) {
requestListener.onFail("");
return;
}
}
requestListener.onSuccess(jsonObject);
}
} catch (JSONException e) {
requestListener.onFail(e.getMessage());
}
requestListener.onSuccess(t);
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
CommonUtils.LogMsg("----------onError---"+e.getMessage()); CommonUtils.LogMsg("----------onError---" + e.getMessage());
requestListener.onFail(e.getMessage()); requestListener.onFail(e.getMessage());
} }

View File

@ -46,7 +46,7 @@ public class RetrofitManager {
// } // }
private synchronized Retrofit getRetrofit() { private synchronized Retrofit getRetrofit() {
if (retrofit == null) { if (retrofit == null) {
long DEFAULT_TIMEOUT = 10; long DEFAULT_TIMEOUT = 5;
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder() OkHttpClient client = new OkHttpClient.Builder()

View File

@ -45,6 +45,10 @@ import java.io.Serializable;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
/**
* 音乐合集或者专辑列表页面
*/
public class CategoryListActivity extends BaseActivity<ActivityCategoryListBinding> implements HomeItemClickListener { public class CategoryListActivity extends BaseActivity<ActivityCategoryListBinding> implements HomeItemClickListener {
@ -52,6 +56,7 @@ public class CategoryListActivity extends BaseActivity<ActivityCategoryListBindi
private VMApplication vmApplication; private VMApplication vmApplication;
private ResponseCategoryList mCategoryList; private ResponseCategoryList mCategoryList;
private String mPageType;
@Override @Override
protected ActivityCategoryListBinding getViewBinding() { protected ActivityCategoryListBinding getViewBinding() {
@ -69,12 +74,14 @@ public class CategoryListActivity extends BaseActivity<ActivityCategoryListBindi
} }
if (!intent.hasExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY)) { if (!intent.hasExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY)) {
return; return;
} }
ResponseCategory category = (ResponseCategory) intent.getSerializableExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY); ResponseCategory category = (ResponseCategory) intent.getSerializableExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY);
if (category == null) if (category == null)
return; return;
mPageType = category.getPageType();
vb.pbLoading.setVisibility(View.VISIBLE); vb.pbLoading.setVisibility(View.VISIBLE);
vm.getList(category.getBrowseId()); vm.getList(category.getBrowseId());
vm.data.observe(this, new Observer<ResponseCategoryList>() { vm.data.observe(this, new Observer<ResponseCategoryList>() {
@ -131,7 +138,6 @@ public class CategoryListActivity extends BaseActivity<ActivityCategoryListBindi
vb.recyclerview.setLayoutManager(new LinearLayoutManager(this)); vb.recyclerview.setLayoutManager(new LinearLayoutManager(this));
adapterCategoryList.setData(info.getList()); adapterCategoryList.setData(info.getList());
vb.recyclerview.setAdapter(adapterCategoryList); vb.recyclerview.setAdapter(adapterCategoryList);
loadCovert(info.getCovert()); loadCovert(info.getCovert());
} }

View File

@ -5,7 +5,6 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.util.Pair;
import android.view.View; import android.view.View;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
@ -35,12 +34,12 @@ import com.hi.music.player.adapter.AdapterPlayList;
import com.hi.music.player.api.MediaControllerListener; import com.hi.music.player.api.MediaControllerListener;
import com.hi.music.player.api.onImageColorListener; import com.hi.music.player.api.onImageColorListener;
import com.hi.music.player.databinding.ActivityPlayBinding; import com.hi.music.player.databinding.ActivityPlayBinding;
import com.hi.music.player.dialog.DialogPlayList;
import com.hi.music.player.helper.CommonUtils; import com.hi.music.player.helper.CommonUtils;
import com.hi.music.player.helper.MyValue; import com.hi.music.player.helper.MyValue;
import com.hi.music.player.javabean.CustomerUrlInfo; import com.hi.music.player.javabean.CustomerUrlInfo;
import com.hi.music.player.javabean.response.ResponsePlayListInfo; import com.hi.music.player.javabean.response.ResponsePlayListInfo;
import com.hi.music.player.javabean.response.ResponsePlayUrl; import com.hi.music.player.javabean.response.ResponsePlayUrl;
import com.hi.music.player.javabean.response.child.ResponseCategory;
import com.hi.music.player.javabean.response.child.ResponseSingle; import com.hi.music.player.javabean.response.child.ResponseSingle;
import com.hi.music.player.media3.MyMediaControllerManager; import com.hi.music.player.media3.MyMediaControllerManager;
import com.hi.music.player.ui.activity.viewmodel.VMApplication; import com.hi.music.player.ui.activity.viewmodel.VMApplication;
@ -87,7 +86,7 @@ public class PlayActivity extends BaseActivity<ActivityPlayBinding> implements S
//-------单曲进入播放列表接口请求需要的参数 //-------单曲进入播放列表接口请求需要的参数
private String playlistId, videoId, params, musicVideoType; private String playlistId, videoId, params, musicVideoType = "";
//-------单曲进入播放列表接口请求需要的参数 //-------单曲进入播放列表接口请求需要的参数
private int mDefaultPlayStartIndex = 0; private int mDefaultPlayStartIndex = 0;
@ -114,7 +113,7 @@ public class PlayActivity extends BaseActivity<ActivityPlayBinding> implements S
videoId = responseSingle.getVideoId(); videoId = responseSingle.getVideoId();
params = responseSingle.getParams(); params = responseSingle.getParams();
musicVideoType = responseSingle.getMusicVideoType(); musicVideoType = responseSingle.getMusicVideoType();
vmPlay.getPlayMusicList(playlistId,videoId,params,musicVideoType); vmPlay.getPlayMusicList(playlistId, videoId, params, musicVideoType);
vmPlay.playList.observe(this, new Observer<List<ResponsePlayListInfo>>() { vmPlay.playList.observe(this, new Observer<List<ResponsePlayListInfo>>() {
@Override @Override
public void onChanged(List<ResponsePlayListInfo> listInfos) { public void onChanged(List<ResponsePlayListInfo> listInfos) {
@ -124,9 +123,24 @@ public class PlayActivity extends BaseActivity<ActivityPlayBinding> implements S
break; break;
case MyValue.TYPE_ENTER_SOURCE_CATEGORY: case MyValue.TYPE_ENTER_SOURCE_CATEGORY:
ResponsePlayListInfo playListInfo = (ResponsePlayListInfo) intent.getSerializableExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY_LIST); ResponsePlayListInfo playListInfo = (ResponsePlayListInfo) intent.getSerializableExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY_LIST);
mDefaultPlayStartIndex = intent.getIntExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY_LIST_INDEX,mDefaultPlayStartIndex); mDefaultPlayStartIndex = intent.getIntExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY_LIST_INDEX, mDefaultPlayStartIndex);
videoId = playListInfo.getVideoId(); videoId = playListInfo.getVideoId();
CommonUtils.LogMsg("--------更新---videoId="+videoId); CommonUtils.LogMsg("--------更新---videoId=" + videoId);
break;
case MyValue.TYPE_ENTER_SOURCE_MV:
ResponseCategory responseCategory = (ResponseCategory) intent.getSerializableExtra(MyValue.KEY_PLAY_ACTIVITY_MV);
videoId = responseCategory.getVideoId();
playlistId = responseCategory.getPlayListId();
params = responseCategory.getParams();
musicVideoType = responseCategory.getMusicVideoType();
vmPlay.getPlayMusicList(playlistId, videoId, params, musicVideoType);
vmPlay.playList.observe(this, new Observer<List<ResponsePlayListInfo>>() {
@Override
public void onChanged(List<ResponsePlayListInfo> listInfos) {
vmApplication.reSetPlayList(listInfos);
}
});
break; break;
} }
@ -143,7 +157,7 @@ public class PlayActivity extends BaseActivity<ActivityPlayBinding> implements S
vb.linearRetry.setVisibility(View.VISIBLE); vb.linearRetry.setVisibility(View.VISIBLE);
return; return;
} }
CommonUtils.LogMsg("--------更新-playList " + playList.size()+"--videoId="+videoId); CommonUtils.LogMsg("--------更新-playList " + playList.size() + "--videoId=" + videoId);
if (playList.size() > 0) { if (playList.size() > 0) {
mPlayList = playList; mPlayList = playList;
musicInfo = playList.get(0); musicInfo = playList.get(0);
@ -445,9 +459,9 @@ public class PlayActivity extends BaseActivity<ActivityPlayBinding> implements S
//重试按钮 //重试按钮
vb.linearRetry.setVisibility(View.GONE); vb.linearRetry.setVisibility(View.GONE);
if (netError == 0) { if (netError == 0) {
switch (mEnterType){ switch (mEnterType) {
case MyValue.TYPE_ENTER_SOURCE_SINGLE: case MyValue.TYPE_ENTER_SOURCE_SINGLE:
vmPlay.getPlayMusicList(playlistId,videoId,params,musicVideoType); vmPlay.getPlayMusicList(playlistId, videoId, params, musicVideoType);
break; break;
} }

View File

@ -42,10 +42,10 @@ public class VMPlay extends ViewModel {
} }
@Override @Override
public void onSuccess(ResponseBody data) { public void onSuccess(JSONObject data) {
JSONObject jsonObject = CommonUtils.toJsonObject(data); // JSONObject jsonObject = CommonUtils.toJsonObject(data);
if (jsonObject != null) { if (data != null) {
List<ResponsePlayListInfo> responsePlayListInfos = JsonHelper.ResolvePlayListJson(jsonObject); List<ResponsePlayListInfo> responsePlayListInfos = JsonHelper.ResolvePlayListJson(data);
_playList.setValue(responsePlayListInfos); _playList.setValue(responsePlayListInfos);
} else { } else {
_playList.setValue(null); _playList.setValue(null);
@ -68,10 +68,10 @@ public class VMPlay extends ViewModel {
} }
@Override @Override
public void onSuccess(ResponseBody data) { public void onSuccess(JSONObject data) {
JSONObject jsonObject = CommonUtils.toJsonObject(data); // JSONObject jsonObject = CommonUtils.toJsonObject(data);
if (jsonObject != null) { if (data != null) {
ResponsePlayUrl responsePlayUrl = JsonHelper.ResolvePlayUrlJson(jsonObject); ResponsePlayUrl responsePlayUrl = JsonHelper.ResolvePlayUrlJson(data);
if(responsePlayUrl == null){ if(responsePlayUrl == null){
// TODO: 2024/9/27 // TODO: 2024/9/27
return; return;

View File

@ -69,8 +69,12 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding> implements H
vmHome.data.observe(getViewLifecycleOwner(), new Observer<ResponseHome>() { vmHome.data.observe(getViewLifecycleOwner(), new Observer<ResponseHome>() {
@Override @Override
public void onChanged(ResponseHome responseHome) { public void onChanged(ResponseHome responseHome) {
if(responseHome == null)return; if(responseHome == null){
requestCount--;
return;
}
List<ResponseHomeChild> childList1 = responseHome.getChildList(); List<ResponseHomeChild> childList1 = responseHome.getChildList();
if(childList1 == null) return;
childList.addAll(childList1); childList.addAll(childList1);
adapterHome.removeLoadingFooter(); adapterHome.removeLoadingFooter();
adapterHome.addData(childList1); adapterHome.addData(childList1);
@ -90,8 +94,9 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding> implements H
CommonUtils.LogMsg("------loadmore--"); CommonUtils.LogMsg("------loadmore--");
adapterHome.addLoadingFooter(); adapterHome.addLoadingFooter();
vmHome.getHomeMore(); vmHome.getHomeMore();
requestCount++;
} }
requestCount++;
} }
} }
}); });
@ -113,9 +118,19 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding> implements H
public void onClickItemCategory(ResponseCategory data) { public void onClickItemCategory(ResponseCategory data) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if(activity!= null){ if(activity!= null){
Intent intent = new Intent(activity, CategoryListActivity.class); String pageType = data.getPageType();
intent.putExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY, data); if(pageType.equals(MyValue.PAGE_TYPE_MV)){
startActivity(intent); Intent intent = new Intent(activity, PlayActivity.class);
intent.putExtra(MyValue.KEY_PLAY_ACTIVITY_MV, data);
intent.putExtra(MyValue.KEY_ENTER_SOURCE, MyValue.TYPE_ENTER_SOURCE_MV);
startActivity(intent);
}else {
Intent intent = new Intent(activity, CategoryListActivity.class);
intent.putExtra(MyValue.KEY_PLAY_ACTIVITY_CATEGORY, data);
startActivity(intent);
}
} }
} }
} }

View File

@ -30,10 +30,10 @@ public class VMCategoryList extends ViewModel {
} }
@Override @Override
public void onSuccess(ResponseBody data) { public void onSuccess(JSONObject data) {
JSONObject jsonObject = CommonUtils.toJsonObject(data); // JSONObject jsonObject = CommonUtils.toJsonObject(data);
if (jsonObject != null) { if (data != null) {
ResponseCategoryList responseCategoryList = JsonHelper.ResolveCategoryList(jsonObject); ResponseCategoryList responseCategoryList = JsonHelper.ResolveCategoryList(data);
_data.setValue(responseCategoryList); _data.setValue(responseCategoryList);
} }
} }

View File

@ -31,10 +31,10 @@ public class VMHome extends ViewModel {
} }
@Override @Override
public void onSuccess(ResponseBody data) { public void onSuccess(JSONObject data) {
JSONObject jsonObject = CommonUtils.toJsonObject(data); // JSONObject jsonObject = CommonUtils.toJsonObject(data);
if (jsonObject != null) { if (data != null) {
ResponseHome responseHome = JsonHelper.ResolveHomeJson(jsonObject); ResponseHome responseHome = JsonHelper.ResolveHomeJson(data);
continuation = responseHome.getContinuation(); continuation = responseHome.getContinuation();
clickTrackingParams = responseHome.getClickTrackingParams(); clickTrackingParams = responseHome.getClickTrackingParams();
@ -58,10 +58,10 @@ public class VMHome extends ViewModel {
} }
@Override @Override
public void onSuccess(ResponseBody data) { public void onSuccess(JSONObject data) {
JSONObject jsonObject = CommonUtils.toJsonObject(data); // JSONObject jsonObject = CommonUtils.toJsonObject(data);
if (jsonObject != null) { if (data != null) {
ResponseHome responseHome = JsonHelper.ResolveHomeMoreJson(jsonObject); ResponseHome responseHome = JsonHelper.ResolveHomeMoreJson(data);
continuation = responseHome.getContinuation(); continuation = responseHome.getContinuation();
clickTrackingParams = responseHome.getClickTrackingParams(); clickTrackingParams = responseHome.getClickTrackingParams();

View File

@ -74,6 +74,9 @@
android:layout_below="@id/tvTitle" android:layout_below="@id/tvTitle"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:gravity="center"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp" /> android:textSize="14sp" />

View File

@ -31,7 +31,7 @@
android:layout_marginStart="40dp" android:layout_marginStart="40dp"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:layout_marginEnd="40dp" android:layout_marginEnd="40dp"
android:scaleType="fitXY" android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher" android:src="@mipmap/ic_launcher"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"

View File

@ -9,9 +9,8 @@
<ImageView <ImageView
android:id="@+id/header" android:id="@+id/header"
android:layout_width="169dp" android:layout_width="170dp"
android:layout_height="169dp" android:layout_height="170dp"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" /> android:src="@mipmap/ic_launcher" />
<TextView <TextView

View File

@ -6,34 +6,48 @@
android:paddingTop="5dp" android:paddingTop="5dp"
android:paddingBottom="5dp"> android:paddingBottom="5dp">
<ImageView <LinearLayout
android:id="@+id/image" android:id="@+id/left_layout"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="60dp" /> android:layout_height="60dp">
<ImageView
android:id="@+id/image"
android:layout_width="60dp"
android:layout_height="60dp"
android:visibility="gone" />
<TextView
android:id="@+id/tv_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/image"
android:layout_marginStart="12dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginStart="12dp"
android:layout_toEndOf="@id/left_layout"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/tv_song_name" android:id="@+id/tv_song_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="15sp" android:textSize="15sp" />
android:text="@string/app_name"/>
<TextView <TextView
android:id="@+id/tv_singer_name" android:id="@+id/tv_singer_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/white_60_color"
android:text="@string/app_name" android:text="@string/app_name"
android:textColor="@color/white_60_color"
android:textSize="12sp" /> android:textSize="12sp" />
</LinearLayout> </LinearLayout>