继续接入爱趣听,基本可用
This commit is contained in:
@@ -55,7 +55,7 @@ android {
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'src/independent/AndroidManifest.xml'
|
||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||
}
|
||||
launcher {
|
||||
manifest.srcFile 'src/launcher/AndroidManifest.xml'
|
||||
|
||||
@@ -14,7 +14,8 @@ import com.mogo.module.apps.R;
|
||||
* 基础类:均衡器、方控学习、蓝牙、FM、车载设置、AUX
|
||||
*/
|
||||
public enum AppEnum {
|
||||
|
||||
// 爱趣听
|
||||
WeCarFlow("爱趣听","com.tencent.wecarflow", R.drawable.module_apps_ic_qq_music ),
|
||||
//"QQ音乐",
|
||||
QQMusic( "QQ音乐", "com.pvetec.musics", R.drawable.module_apps_ic_qq_music ),
|
||||
|
||||
|
||||
@@ -11,11 +11,9 @@ import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.module.media.widget.MediaWindow2;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
import com.mogo.service.module.ModuleType;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
@Route( path = MediaConstants.TAG )
|
||||
public class MediaCardViewProvider implements IMogoModuleProvider {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.module.media.widget;
|
||||
package com.mogo.module.media;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -7,15 +7,18 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.module.media.R;
|
||||
import com.mogo.module.media.ServiceMediaHandler;
|
||||
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.WeCarFlowPresenter;
|
||||
import com.mogo.module.media.utils.LaunchUtils;
|
||||
import com.mogo.module.media.utils.MusicControlBroadCast;
|
||||
import com.mogo.module.media.utils.Utils;
|
||||
import com.mogo.module.media.view.IMusicView;
|
||||
import com.mogo.module.media.widget.AnimCircleImageView;
|
||||
import com.mogo.module.media.widget.NoScrollSeekBar;
|
||||
import com.mogo.module.media.widget.ScrollingTextView;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.glide.GlideApp;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
@@ -46,13 +49,6 @@ public class MediaWindow2 implements IMusicView {
|
||||
private boolean mTwoChange = false;
|
||||
private boolean isFirstPlay = false;
|
||||
|
||||
private Runnable mRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MusicControlBroadCast.sendGetMusicPlayStateBroadcast();
|
||||
}
|
||||
};
|
||||
|
||||
public void initMedia(Context context) {
|
||||
mContext = context;
|
||||
mPresenter = new WeCarFlowPresenter(this);
|
||||
@@ -91,26 +87,22 @@ public class MediaWindow2 implements IMusicView {
|
||||
mWindowMediaCenter.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
public void onClicks(View view) {
|
||||
if (mMediaInfoData != null) {
|
||||
MusicControlBroadCast.openMediaApp(mMediaInfoData.getType());
|
||||
} else {
|
||||
MusicControlBroadCast.openMediaApp(1);
|
||||
}
|
||||
openAqtApp();
|
||||
}
|
||||
});
|
||||
|
||||
mWindowPlayPause.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
public void onClicks(View view) {
|
||||
if (isFirstPlay) {
|
||||
if (mMediaInfoData != null) {
|
||||
MusicControlBroadCast.listeningSendData(mMediaInfoData);
|
||||
}
|
||||
} else {
|
||||
if (mMediaInfoData != null) {
|
||||
MusicControlBroadCast.commandPlayPause(mMediaInfoData.getType(),
|
||||
mMediaInfoData.getPlayState());
|
||||
if (mMediaInfoData != null) {
|
||||
if (mMediaInfoData.getPlayState() == MusicConstant.PLAY_STATE_PAUSE_OR_STOP) {
|
||||
mPresenter.play(mMediaInfoData);
|
||||
}else{
|
||||
// 没有做详细判断,不是暂停就是播放
|
||||
mPresenter.pause(mMediaInfoData);
|
||||
}
|
||||
}else{
|
||||
openAqtApp();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -118,8 +110,8 @@ public class MediaWindow2 implements IMusicView {
|
||||
mWindowPlayNext.setOnClickListener(new NoDoubleClickListener() {
|
||||
@Override
|
||||
public void onClicks(View view) {
|
||||
if (mMediaInfoData != null) {
|
||||
MusicControlBroadCast.commandNext(mMediaInfoData.getType());
|
||||
if (mPresenter != null) {
|
||||
mPresenter.next();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -171,11 +163,8 @@ public class MediaWindow2 implements IMusicView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMusicPlaying(MediaInfoData mediaInfoData) {
|
||||
Logger.d(TAG, "onMusicPlaying: " + mediaInfoData);
|
||||
addWindowView();
|
||||
mMediaInfoData = mediaInfoData;
|
||||
updateWindowUI();
|
||||
public void onMusicPlaying() {
|
||||
Logger.d(TAG, "onMusicPlaying");
|
||||
if (mWindowPlayPause != null) {
|
||||
mWindowPlayPause.setImageResource(R.drawable.module_media_window_pop_play);
|
||||
}
|
||||
@@ -186,10 +175,8 @@ public class MediaWindow2 implements IMusicView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMusicPause(MediaInfoData mediaInfoData) {
|
||||
Logger.d(TAG, "onMusicPause: " + mediaInfoData);
|
||||
mMediaInfoData = mediaInfoData;
|
||||
updateWindowUI();
|
||||
public void onMusicPause() {
|
||||
Logger.d(TAG, "onMusicPause: ");
|
||||
if (mWindowPlayPause != null) {
|
||||
mWindowPlayPause.setImageResource(R.drawable.module_media_window_pop_pause);
|
||||
}
|
||||
@@ -200,23 +187,34 @@ public class MediaWindow2 implements IMusicView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMusicStoped(MediaInfoData mediaInfoData) {
|
||||
Logger.d(TAG, "onMusicStoped: " + mediaInfoData);
|
||||
mMediaInfoData = mediaInfoData;
|
||||
updateWindowUI();
|
||||
public void onMusicStopped() {
|
||||
Logger.d(TAG, "onMusicStopped");
|
||||
if (mWindowPlayPause != null) {
|
||||
mWindowPlayPause.setImageResource(R.drawable.module_media_window_pop_pause);
|
||||
}
|
||||
|
||||
|
||||
if (mCircleImg != null) {
|
||||
mCircleImg.stopAnim();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaInfoChanged(MediaInfoData mediaInfoData) {
|
||||
if(!isFirstPlay) {
|
||||
mMediaInfoData = mediaInfoData;
|
||||
addWindowView();
|
||||
updateWindowUI();
|
||||
}
|
||||
isFirstPlay = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMusicProgress(long current, long total) {
|
||||
Logger.d(TAG, "onMusicProgress==current: " + current + " total: " + total);
|
||||
// Logger.d(TAG, "onMusicProgress==current: " + current + " total: " + total);
|
||||
if(mMediaInfoData!=null) {
|
||||
mMediaInfoData.setCurTime((int) current);
|
||||
mMediaInfoData.setMaxTime((int) total);
|
||||
}
|
||||
if (mWindowCurrTime != null) {
|
||||
mWindowCurrTime.setText(Utils.calculateTime((int) current));
|
||||
mWindowMaxTime.setText(Utils.calculateTime((int) total));
|
||||
@@ -231,4 +229,12 @@ public class MediaWindow2 implements IMusicView {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void openAqtApp(){
|
||||
try {
|
||||
LaunchUtils.launchByPkg(mContext,"com.tencent.wecarflow");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,4 +142,13 @@ public class MediaInfoData implements Serializable {
|
||||
public void setBookInfo(String bookInfo) {
|
||||
this.bookInfo = bookInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MediaInfoData{" +
|
||||
"mediaName='" + mediaName + '\'' +
|
||||
", mediaImg='" + mediaImg + '\'' +
|
||||
", playState=" + playState +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,22 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.module.media.MediaConstants;
|
||||
import com.mogo.module.media.constants.MusicConstant;
|
||||
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 com.tencent.wecarflow.flowoutside.sdk.BindListener;
|
||||
import com.tencent.wecarflow.flowoutside.sdk.FlowPlayControl;
|
||||
import com.tencent.wecarflow.flowoutside.sdk.MediaChangeListener;
|
||||
import com.tencent.wecarflow.flowoutside.sdk.MediaInfo;
|
||||
import com.tencent.wecarflow.flowoutside.sdk.PlayStateListener;
|
||||
import com.tencent.wecarflow.flowoutside.sdk.QueryCallback;
|
||||
|
||||
/**
|
||||
* 爱趣听presenter
|
||||
@@ -31,33 +37,94 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
|
||||
private MediaInfoData currentMedia;
|
||||
|
||||
private boolean isBind = true;
|
||||
private IMogoServiceApis serviceApis;
|
||||
|
||||
private QueryCallback<Boolean> isPlayingCallback = new QueryCallback<Boolean>() {
|
||||
@Override
|
||||
public void onError(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Boolean aBoolean) {
|
||||
currentMedia.setPlayState(aBoolean ? MusicConstant.PLAY_STATE_PLAYING :
|
||||
MusicConstant.PLAY_STATE_PAUSE_OR_STOP);
|
||||
if (mView != null) {
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private QueryCallback<MediaInfo> currentCallback = new QueryCallback<MediaInfo>() {
|
||||
@Override
|
||||
public void onError(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(MediaInfo mediaInfo) {
|
||||
currentMedia.setMediaName(mediaInfo.getMediaName());
|
||||
currentMedia.setMediaImg(mediaInfo.getMediaImage());
|
||||
if (mView != null) {
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
FlowPlayControl.getInstance().bindPlayService(context);
|
||||
currentMedia = new MediaInfoData();
|
||||
currentMedia.setPlayState(MusicConstant.PLAY_STATE_PAUSE_OR_STOP);
|
||||
|
||||
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) {
|
||||
// 未绑定,需要重新绑定,同时第一次绑定初始化也是在此处
|
||||
FlowPlayControl.getInstance().bindPlayService(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FlowPlayControl.getInstance().addBindListener(new BindListener() {
|
||||
@Override
|
||||
public void onServiceConnected() {
|
||||
Logger.d(TAG, "onServiceConnected===");
|
||||
isBind = true;
|
||||
FlowPlayControl.getInstance().queryPlaying(isPlayingCallback);
|
||||
FlowPlayControl.getInstance().queryCurrent(currentCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected() {
|
||||
Logger.e(TAG, "onServiceDisconnected===");
|
||||
isBind = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindDied() {
|
||||
Logger.e(TAG, "onBindDied===");
|
||||
isBind = false;
|
||||
}
|
||||
});
|
||||
|
||||
FlowPlayControl.getInstance().addMediaChangeListener(new MediaChangeListener() {
|
||||
@Override
|
||||
public void onMediaChange(MediaInfo mediaInfo) {
|
||||
currentMedia = new MediaInfoData();
|
||||
Logger.d(TAG, "onMediaChange: " + mediaInfo);
|
||||
Logger.d(TAG, "onMediaChange, img: " + mediaInfo.getMediaImage());
|
||||
currentMedia.setMediaName(mediaInfo.getMediaName());
|
||||
currentMedia.setMediaUrl(mediaInfo.getMediaImage());
|
||||
currentMedia.setMediaImg(mediaInfo.getMediaImage());
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +138,8 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
public void onStart() {
|
||||
if (mView != null && currentMedia != null) {
|
||||
currentMedia.setPlayState(MusicConstant.PLAY_STATE_PLAYING);
|
||||
mView.onMusicPlaying(currentMedia);
|
||||
mView.onMusicPlaying();
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +147,8 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
public void onPause() {
|
||||
if (mView != null && currentMedia != null) {
|
||||
currentMedia.setPlayState(MusicConstant.PLAY_STATE_PAUSE_OR_STOP);
|
||||
mView.onMusicPause(currentMedia);
|
||||
mView.onMusicPause();
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +156,8 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
public void onStop() {
|
||||
if (mView != null && currentMedia != null) {
|
||||
currentMedia.setPlayState(MusicConstant.PLAY_STATE_PAUSE_OR_STOP);
|
||||
mView.onMusicStoped(currentMedia);
|
||||
mView.onMusicStopped();
|
||||
mView.onMediaInfoChanged(currentMedia);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +168,8 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FlowPlayControl.getInstance().bindPlayService(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,12 +196,4 @@ public class WeCarFlowPresenter extends BaseMediaPresenter<IMusicView> {
|
||||
public void next() {
|
||||
FlowPlayControl.getInstance().doNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(@NonNull LifecycleOwner owner) {
|
||||
super.onDestroy(owner);
|
||||
if (context != null) {
|
||||
FlowPlayControl.getInstance().unbindPlayService(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.module.media.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-02-03
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class LaunchUtils {
|
||||
|
||||
/**
|
||||
* 通过包名启动app
|
||||
*
|
||||
* @param context
|
||||
* @param pkg 包名
|
||||
*/
|
||||
public static void launchByPkg( Context context, String pkg ) throws Exception {
|
||||
Intent intent = getLaunchIntentForPackage( context, pkg );
|
||||
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
context.startActivity( intent );
|
||||
}
|
||||
|
||||
public static Intent getLaunchIntentForPackage( Context context, String pkg ) {
|
||||
return context.getPackageManager().getLaunchIntentForPackage( pkg );
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@ import com.mogo.module.media.model.MediaInfoData;
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public interface IMusicView extends IView {
|
||||
void onMusicPlaying(MediaInfoData mediaInfoData);
|
||||
void onMediaInfoChanged(MediaInfoData mediaInfoData);
|
||||
|
||||
void onMusicPause(MediaInfoData mediaInfoData);
|
||||
void onMusicPlaying();
|
||||
|
||||
void onMusicStoped(MediaInfoData mediaInfoData);
|
||||
void onMusicPause();
|
||||
|
||||
void onMusicStopped();
|
||||
|
||||
void onMusicProgress(long current,long total);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user