|
@@ -4,6 +4,7 @@ import android.Manifest;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.IntentFilter;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
@@ -18,7 +19,7 @@ import android.widget.FrameLayout;
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
import com.cooleshow.base.router.RouterPath;
|
|
|
-import com.cooleshow.base.service.PlayMusicService;
|
|
|
+import com.cooleshow.base.service.PlayMusicReceiver;
|
|
|
import com.cooleshow.base.ui.activity.BaseActivity;
|
|
|
import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
import com.cooleshow.base.utils.FileUtils;
|
|
@@ -96,10 +97,10 @@ public class AccompanyActivity extends BaseActivity<ActivityAccompanyBinding> {
|
|
|
private String accompanimentUrl; //当前曲子伴奏mp3地址
|
|
|
private AccompanyFragment accompanyFragment;
|
|
|
private JSONObject baseJsonObject;
|
|
|
- private Intent intentOne;
|
|
|
private boolean isNeedResetScreenOrientation = true;
|
|
|
|
|
|
private Handler mHandler = new Handler(Looper.getMainLooper());
|
|
|
+ private PlayMusicReceiver mReceiver;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
@@ -308,8 +309,8 @@ public class AccompanyActivity extends BaseActivity<ActivityAccompanyBinding> {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void openAdjustRecording(String recordId, String title, String coverImg,float speed) {
|
|
|
- goAdjustMusic(recordId, title, coverImg,speed);
|
|
|
+ public void openAdjustRecording(String recordId, String title, String coverImg, float speed) {
|
|
|
+ goAdjustMusic(recordId, title, coverImg, speed);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -337,9 +338,12 @@ public class AccompanyActivity extends BaseActivity<ActivityAccompanyBinding> {
|
|
|
.add(R.id.fl_webview, accompanyFragment)
|
|
|
.commitAllowingStateLoss();
|
|
|
|
|
|
+ registerBroadCast();
|
|
|
+ }
|
|
|
|
|
|
- intentOne = new Intent(this, PlayMusicService.class);
|
|
|
- startService(intentOne);
|
|
|
+ private void registerBroadCast() {
|
|
|
+ mReceiver = new PlayMusicReceiver();
|
|
|
+ registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
|
|
|
}
|
|
|
|
|
|
private void addToken(String url) {
|
|
@@ -405,7 +409,7 @@ public class AccompanyActivity extends BaseActivity<ActivityAccompanyBinding> {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- private void goAdjustMusic(String recordId, String title, String coverImg,float speed) {
|
|
|
+ private void goAdjustMusic(String recordId, String title, String coverImg, float speed) {
|
|
|
if (TextUtils.isEmpty(accompanimentUrl)) {
|
|
|
ToastUtil.getInstance().showShort("无法找到伴奏文件");
|
|
|
return;
|
|
@@ -554,12 +558,14 @@ public class AccompanyActivity extends BaseActivity<ActivityAccompanyBinding> {
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
+ try {
|
|
|
+ unregisterReceiver(mReceiver);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
if (mHandler != null) {
|
|
|
mHandler.removeCallbacksAndMessages(null);
|
|
|
}
|
|
|
- if (intentOne != null) {
|
|
|
- stopService(intentOne);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|