Skip to content

Commit

Permalink
更新musicApi版本到1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
caiyonglong committed Apr 25, 2021
1 parent c3de344 commit f6aad14
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# 计划
- [ ] 整理文档
- [musicApi接入和调试文档](./doc/音乐接口组件库接入.md)
- [ ] 代码重构

# 相关项目|音乐API
Expand All @@ -45,6 +46,13 @@
- [More..](https://github.com/caiyonglong/MusicLake/blob/develop/app/build.gradle)

# 软件运行截图



因为github限制,所有图片预览需要翻强或者git clone到本地才能预览



<p>
<img src="screenshots/preview1.png" width="225" height="400"/>
<img src="screenshots/preview2.png" width="225" height="400"/>
Expand Down
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ android {
}

dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
Expand Down Expand Up @@ -160,7 +160,7 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1'

//bugly的仓库
implementation 'com.tencent.bugly:crashreport_upgrade:1.4.2'
implementation 'com.tencent.bugly:crashreport_upgrade:1.5.0'
// implementation 'com.tencent.bugly:nativecrashreport:3.7.1'

//微博
Expand All @@ -173,13 +173,13 @@ dependencies {


//youtube接口
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.api-client:google-api-client-android:1.23.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev198-1.23.0'
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3'

//Android音乐接口Api
implementation 'com.github.caiyonglong:musicapi:1.1.3'
//Android音乐接口Api, 远程和本地只能保留一个!!
implementation 'com.github.caiyonglong:musicapi:1.1.4'
// implementation project(':musicapi')
//缓存
implementation 'com.danikula:videocache:2.7.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object NeteaseApiServiceImpl {
}

/**
* 获取歌单歌曲数据
* 获取歌单数据
*/
fun getTopPlaylists(cat: String, limit: Int): Observable<MutableList<Playlist>> {
return apiService.getTopPlaylist(cat, limit)
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/com/cyl/musiclake/api/net/ApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class ApiManager {
private static ApiManager sApiManager;

private static long CONNECT_TIMEOUT = 60L;
private static long READ_TIMEOUT = 10L;
private static long WRITE_TIMEOUT = 10L;
private static long READ_TIMEOUT = 60L;
private static long WRITE_TIMEOUT = 60L;
//设缓存有效期为1天
private static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
//查询缓存的Cache-Control设置,为if-only-cache时只查询缓存而不会请求服务器,max-stale可以配合设置缓存失效时间
Expand All @@ -72,6 +72,14 @@ public class ApiManager {
}
return chain.proceed(request);
};
/**
* 网络拦截器
*/
private static final Interceptor mNetInterceptor = chain -> {
Request request = chain.request().newBuilder()
.addHeader("Connection", "close").build();
return chain.proceed(request);
};

/**
* 获取OkHttpClient实例
Expand All @@ -96,6 +104,7 @@ private static OkHttpClient getOkHttpClient() {
}

mOkHttpClient = builder.cache(cache)
.addInterceptor(mNetInterceptor)
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
Expand Down Expand Up @@ -173,11 +182,11 @@ public void onError(Throwable e) {
String errorInfo = "";
try {
errorInfo = ((HttpException) e).response().errorBody().string();
if (errorInfo.startsWith("{")){
if (errorInfo.startsWith("{")) {
JSONObject jsonObject = new JSONObject(errorInfo);
String error = jsonObject.getString("msg");
result.error(error);
}else{
} else {
result.error(errorInfo);
}
} catch (IOException | JSONException e1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ constructor() : BasePresenter<PlaylistContract.View>(), PlaylistContract.Present
}

/**
* 加载网易排行榜(0歌曲)
* 加载推荐歌单列表(0歌曲)
*/
fun loadNetease(tag: String) {
val observable = NeteaseApiServiceImpl.getTopPlaylists(tag, 30)
val observable = NeteaseApiServiceImpl.getTopPlaylists(tag, 100)
ApiManager.request(observable, object : RequestCallBack<MutableList<Playlist>> {
override fun success(result: MutableList<Playlist>) {
mView?.showNeteaseCharts(result)
Expand All @@ -121,10 +121,10 @@ constructor() : BasePresenter<PlaylistContract.View>(), PlaylistContract.Present
}

/**
* 加载网易排行榜(0歌曲)
* 加载精品歌单列表(0歌曲)
*/
fun loadHighQualityPlaylist(tag: String) {
val observable = NeteaseApiServiceImpl.getTopPlaylistsHigh(tag, 30, null)
val observable = NeteaseApiServiceImpl.getTopPlaylistsHigh(tag, 100, null)
ApiManager.request(observable, object : RequestCallBack<MutableList<Playlist>> {
override fun success(result: MutableList<Playlist>) {
mView?.showNeteaseCharts(result)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@

<string name="action_share">Share</string>
<string name="action_reply">Reply</string>
<string name="copyright_info">Copyright© 2020 MusicLake Group</string>
<string name="copyright_info">Copyright© 2016-2021 MusicLake Group</string>
<string name="delete_playlist_tips">是否删除这个歌单?</string>
<string name="clear_history_playlist_tips">是否清空播放历史?</string>
<string name="choose_singer">选择歌手</string>
Expand Down
35 changes: 35 additions & 0 deletions doc/音乐接口组件库接入.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# musicApi音乐接口接入文档



为了减少MusicLake工程对音乐api的依赖,方便api调用和版本隔离,特意将音乐相关的api接口和调用方式封住成了一个库。

### 接入方式

在app/build.gradle配置中添加远程依赖
```
implementation 'com.github.caiyonglong:musicapi:1.1.4'
```
### 本地调试musicApi库

一、首先将 [https://github.com/caiyonglong/MusicApi](https://github.com/caiyonglong/MusicApi) 库clone到本地
注意,需要和MusicLake同级目录。

二、修改 setting.gradle

```
include ':musicapi'
project (':musicapi').projectDir = new File('../MusicClientApi/musicapi')
```
三、在 app/build.gradle配置中添加依赖
注释远程依赖库、增加本地musicapi依赖看库

```
implementation project(':musicapi')
```
具体可参考项目中的setting.gradle 和app/build.gradle



**欢迎star 、PR、isuee!!!**

0 comments on commit f6aad14

Please sign in to comment.