添加酷我音乐sdk
This commit is contained in:
@@ -46,6 +46,7 @@ dependencies {
|
||||
|
||||
// 爱趣听sdk上传到了公司的maven,用来规避RELEASE时ClassDefNotFound异常,后续若爱趣听有新的sdk也需要上传maven
|
||||
implementation "com.mogo.tencent.wecarflow:mogo-wecarflow:+@aar"
|
||||
implementation "com.mogo.kwmusic:mogo-kwmusic:+"
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogomap
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
|
||||
import com.mogo.module.media.constants.MusicConstant;
|
||||
import com.mogo.module.media.listener.NoDoubleClickListener;
|
||||
import com.mogo.module.media.model.MediaInfoData;
|
||||
import com.mogo.module.media.presenter.BaseMediaPresenter;
|
||||
import com.mogo.module.media.presenter.KwPresenter;
|
||||
import com.mogo.module.media.presenter.WeCarFlowPresenter;
|
||||
import com.mogo.module.media.utils.Utils;
|
||||
import com.mogo.module.media.view.IMusicView;
|
||||
@@ -35,7 +37,7 @@ public class MediaWindow2 implements IMusicView {
|
||||
|
||||
public static final String TAG = MediaWindow2.class.getName();
|
||||
private Context mContext;
|
||||
private WeCarFlowPresenter mPresenter;
|
||||
private KwPresenter mPresenter;
|
||||
|
||||
private MediaInfoData mMediaInfoData = new MediaInfoData();
|
||||
|
||||
@@ -54,7 +56,7 @@ public class MediaWindow2 implements IMusicView {
|
||||
|
||||
public void initMedia(Context context) {
|
||||
mContext = context;
|
||||
mPresenter = new WeCarFlowPresenter(this);
|
||||
mPresenter = new KwPresenter(this);
|
||||
mPresenter.init(context);
|
||||
|
||||
if(DebugConfig.isLauncher()) {
|
||||
@@ -221,6 +223,8 @@ public class MediaWindow2 implements IMusicView {
|
||||
if (mCircleImg != null) {
|
||||
mCircleImg.stopAnim();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.mogo.module.media.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.module.media.MediaConstants;
|
||||
import com.mogo.module.media.model.MediaInfoData;
|
||||
import com.mogo.module.media.view.IMusicView;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
|
||||
import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import cn.kuwo.autosdk.api.KWAPI;
|
||||
import cn.kuwo.autosdk.api.PlayState;
|
||||
import cn.kuwo.base.bean.Music;
|
||||
|
||||
/**
|
||||
* 适配酷我的presenter
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class KwPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
private static final String TAG = "KwPresenter";
|
||||
private KWAPI kwapi;
|
||||
private boolean isBind = false;
|
||||
|
||||
private Music currentMusic;
|
||||
|
||||
public KwPresenter(IMusicView view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
kwapi = KWAPI.createKWAPI(context, "auto");
|
||||
|
||||
kwapi.registerConnectedListener(b -> {
|
||||
Logger.d(TAG, "onConnected: " + b);
|
||||
isBind = b;
|
||||
if (!isBind) {
|
||||
mView.onMusicStopped();
|
||||
}
|
||||
});
|
||||
|
||||
kwapi.registerExitListener(() -> {
|
||||
Logger.d(TAG, "onExit===");
|
||||
mView.onMusicStopped();
|
||||
});
|
||||
|
||||
kwapi.registerPlayerStatusListener((playerStatus, music) -> {
|
||||
currentMusic = music;
|
||||
MediaInfoData mediaInfoData = new MediaInfoData();
|
||||
mediaInfoData.setMediaName(music.name);
|
||||
mediaInfoData.setMediaImg(music.imageURL);
|
||||
Logger.d(TAG,
|
||||
"onPlayerStatusChange: " + mediaInfoData + " playStatus: " + playerStatus);
|
||||
mView.onMediaInfoChanged(mediaInfoData);
|
||||
switch (playerStatus) {
|
||||
case PLAYING:
|
||||
case BUFFERING:
|
||||
startTrackTrackProgress();
|
||||
mView.onMusicPlaying();
|
||||
break;
|
||||
case PAUSE:
|
||||
stopTrackTrackProgress();
|
||||
mView.onMusicPause();
|
||||
break;
|
||||
case STOP:
|
||||
stopTrackTrackProgress();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
IMogoServiceApis serviceApis =
|
||||
(IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context);
|
||||
|
||||
serviceApis.getStatusManagerApi().registerStatusChangedListener(MediaConstants.MODULE_TYPE, StatusDescriptor.MAIN_PAGE_RESUME, new IMogoStatusChangedListener() {
|
||||
@Override
|
||||
public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) {
|
||||
if (isTrue) {
|
||||
Logger.d(TAG, "onResume, isBind: " + isBind);
|
||||
// 需要在resume时候判断绑定关系是否正常
|
||||
if (!isBind) {
|
||||
// 未绑定,需要重新绑定,同时第一次绑定初始化也是在此处
|
||||
kwapi.bindAutoSdkService();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
kwapi.bindAutoSdkService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void play(MediaInfoData mediaInfoData) {
|
||||
if (kwapi.isKuwoRunning()) {
|
||||
kwapi.setPlayState(PlayState.STATE_PLAY);
|
||||
} else {
|
||||
kwapi.randomPlayMusic();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(MediaInfoData mediaInfoData) {
|
||||
if (kwapi.isKuwoRunning()) {
|
||||
kwapi.setPlayState(PlayState.STATE_PAUSE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(MediaInfoData mediaInfoData) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pre() {
|
||||
if (kwapi.isKuwoRunning()) {
|
||||
kwapi.setPlayState(PlayState.STATE_PRE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
if (kwapi.isKuwoRunning()) {
|
||||
kwapi.setPlayState(PlayState.STATE_NEXT);
|
||||
}
|
||||
}
|
||||
|
||||
private Handler.Callback callback = new Handler.Callback() {
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
if (isTrackingProgress) {
|
||||
mView.onMusicProgress(kwapi.getCurrentMusicDuration(), currentMusic.duration);
|
||||
msg.getTarget().sendEmptyMessageDelayed(MSG_TRACK_PROGRESS, MSG_TRACK_PROGRESS_DELAY);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
private Handler handler = new Handler(callback);
|
||||
private static final int MSG_TRACK_PROGRESS = 1001;
|
||||
private static final long MSG_TRACK_PROGRESS_DELAY = 1000;
|
||||
|
||||
private boolean isTrackingProgress = false;
|
||||
|
||||
private void startTrackTrackProgress() {
|
||||
isTrackingProgress = true;
|
||||
handler.sendEmptyMessageDelayed(MSG_TRACK_PROGRESS, MSG_TRACK_PROGRESS_DELAY);
|
||||
}
|
||||
|
||||
private void stopTrackTrackProgress() {
|
||||
isTrackingProgress = false;
|
||||
handler.removeMessages(MSG_TRACK_PROGRESS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user