Skip to content

Commit

Permalink
修复 playerService 的两个问题,去除 player 库中不必要的依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
KunMinX committed Oct 31, 2019
1 parent 30180db commit 26a9cf2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 44 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/com/kunminx/puremusic/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

PlayerManager.getInstance().getStartService().observe(this, aBoolean -> {
getApplicationContext().startService(new Intent(getApplicationContext(), PlayerService.class));
Intent intent = new Intent(getApplicationContext(), PlayerService.class);
if (aBoolean) {
getApplicationContext().startService(intent);
} else {
getApplicationContext().stopService(intent);
}
});

mMainActivityViewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

package com.kunminx.player.config;
package com.kunminx.puremusic.data.config;

import com.kunminx.architecture.utils.Utils;

/**
* Create by KunMinX at 18/9/28
*/
public class Configs {

public static String CACHE_PATH;
public static String CACHE_PATH = Utils.getApp().getCacheDir().getAbsolutePath();

public static String MUSIC_DOWNLOAD_PATH = CACHE_PATH + "/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ public void requestLastPlayingInfo() {
mController.requestLastPlayingInfo();
}

@Override
public void requestAlbumCover(String coverUrl, String musicId) {
mController.requestAlbumCover(coverUrl, musicId);
}

@Override
public void setSeek(int progress) {
mController.setSeek(progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import com.kunminx.player.config.Configs;
import com.kunminx.player.utils.ImageUtils;
import com.kunminx.puremusic.MainActivity;
import com.kunminx.puremusic.data.bean.TestAlbum;
import com.kunminx.puremusic.player.PlayerManager;
import com.kunminx.puremusic.player.helper.PlayerCallHelper;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Response;
import com.kunminx.puremusic.data.config.Configs;

import java.io.File;

/**
* Create by KunMinX at 19/7/17
Expand Down Expand Up @@ -165,7 +170,7 @@ private void createNotification(TestAlbum.TestMusic testMusic) {
notification.contentView.setImageViewBitmap(com.kunminx.player.R.id.player_album_art, bitmap);
notification.bigContentView.setImageViewBitmap(com.kunminx.player.R.id.player_album_art, bitmap);
} else {
PlayerManager.getInstance().requestAlbumCover(testMusic.getCoverImg(), testMusic.getMusicId());
requestAlbumCover(testMusic.getCoverImg(), testMusic.getMusicId());
notification.contentView.setImageViewResource(com.kunminx.player.R.id.player_album_art, com.kunminx.player.R.drawable.bg_default);
notification.bigContentView.setImageViewResource(com.kunminx.player.R.id.player_album_art, com.kunminx.player.R.drawable.bg_default);
}
Expand Down Expand Up @@ -207,6 +212,16 @@ public void setListeners(RemoteViews view) {
}
}

private void requestAlbumCover(String coverUrl, String musicId) {
OkGo.<File>get(coverUrl)
.execute(new FileCallback(Configs.MUSIC_DOWNLOAD_PATH, musicId + ".jpg") {
@Override
public void onSuccess(Response<File> response) {
startService(new Intent(getApplicationContext(), PlayerService.class));
}
});
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
15 changes: 1 addition & 14 deletions player/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {


defaultConfig {
minSdkVersion 23
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -51,22 +51,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation "androidx.lifecycle:lifecycle-runtime:2.1.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:2.1.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.1.0"

implementation 'com.lzy.net:okgo:3.0.4'
implementation 'com.lzy.net:okrx2:2.0.2'
implementation 'com.lzy.net:okserver:2.0.5'
implementation 'com.google.code.gson:gson:2.8.6'

implementation 'com.danikula:videocache:2.7.1'
}
2 changes: 0 additions & 2 deletions player/src/main/java/com/kunminx/player/IPlayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public interface IPlayController<B extends BaseAlbumItem, M extends BaseMusicIte

void requestLastPlayingInfo();

void requestAlbumCover(String coverUrl, String musicId);

void setSeek(int progress);

String getTrackTime(int progress);
Expand Down
19 changes: 1 addition & 18 deletions player/src/main/java/com/kunminx/player/PlayerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
import androidx.lifecycle.MutableLiveData;

import com.danikula.videocache.HttpProxyCacheServer;
import com.kunminx.player.config.Configs;
import com.kunminx.player.dto.BaseAlbumItem;
import com.kunminx.player.dto.BaseMusicItem;
import com.kunminx.player.dto.ChangeMusic;
import com.kunminx.player.dto.PlayingMusic;
import com.kunminx.player.helper.MediaPlayerHelper;
import com.kunminx.player.helper.PlayerFileNameGenerator;
import com.kunminx.player.utils.NetworkUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.FileCallback;
import com.lzy.okgo.model.Response;

import java.io.File;
import java.util.List;

/**
Expand All @@ -59,8 +54,6 @@ public class PlayerController<B extends BaseAlbumItem, M extends BaseMusicItem>

public void init(Context context) {

Configs.CACHE_PATH = context.getApplicationContext().getCacheDir().getAbsolutePath();

mPlayingInfoManager.init(context.getApplicationContext());

proxy = new HttpProxyCacheServer.Builder(context.getApplicationContext())
Expand Down Expand Up @@ -177,16 +170,6 @@ public void requestLastPlayingInfo() {
pauseLiveData.setValue(mIsPaused);
}

public void requestAlbumCover(String coverUrl, String musicId) {
OkGo.<File>get(coverUrl)
.execute(new FileCallback(Configs.MUSIC_DOWNLOAD_PATH, musicId + ".jpg") {
@Override
public void onSuccess(Response<File> response) {
startForegroundService.setValue(true);
}
});
}

public void setSeek(int progress) {
MediaPlayerHelper.getInstance().getMediaPlayer().seekTo(progress);
}
Expand Down Expand Up @@ -257,7 +240,7 @@ public void clear(Context context) {
//这里设为true是因为可能通知栏清除后,还可能在页面中点击播放
resetIsChangingPlayingChapter(context);
MediaPlayerHelper.getInstance().setProgressInterval(1000).setMediaPlayerHelperCallBack(null);
startForegroundService.setValue(true);
startForegroundService.setValue(false);
}

public void resetIsChangingPlayingChapter(Context context) {
Expand Down

0 comments on commit 26a9cf2

Please sign in to comment.