Commit 448abcc2 by 刘鹏

feat: PlayService移除

parent 8cc2f486
......@@ -33,7 +33,6 @@ import com.ydl.component.mvp.DemoPresenter
import com.ydl.component.route.PlatformTempCommonRouteImpl
import com.ydl.component.rtc.MDTLoginActivity
import com.ydl.confide.home.ConfideHomeActivity
import com.ydl.media.audio.PlayService
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.mvp.lce.BaseLceActivity
......@@ -77,11 +76,6 @@ import kotlin.math.roundToInt
@Route(path = "/main/main")
class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(),
DemoContract.View {
// private var secretDescriptionDialog: SecretDescriptionDialog? = null
private var serviceConnection: ServiceConnection? = null
private var secretDialog: SecretDialog? = null
protected var playService: PlayService? = null
private var mFloatDisposable:Disposable?=null
......@@ -295,9 +289,6 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
private fun bindService() {
val intent = Intent()
intent.setClass(this, PlayService::class.java!!)
serviceConnection = PlayServiceConnection()
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
}
private fun initMeditationObserver(){
......@@ -317,11 +308,6 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
override fun onResume() {
super.onResume()
MobclickAgent.onResume(this)
// ModularServiceManager.provide(IConsultantService::class.java)
// .
// (this)
val trtcCalling = TRTCCalling.sharedInstance(this)
if (!TextUtils.isEmpty(trtcCalling.mRoomId) && !TextUtils.isEmpty(trtcCalling.mUserId)) {
val intent = Intent(mContext, YDLInvitionActivity::class.java)
......@@ -333,11 +319,7 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
}
}
override fun onPause() {
super.onPause()
// ModularServiceManager.provide(IConsultantService::class.java).hideConsultAssistantDialog()
}
fun onEvent(event: MeditationFloatEvent) {
......@@ -345,10 +327,6 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
@SuppressLint("MissingSuperCall")
override fun onDestroy() {
if (serviceConnection != null) {
unbindService(serviceConnection)
}
MediaPlayerManager.getInstance(this)?.stop()
hideFloatWindow()
......@@ -362,33 +340,6 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
super.onDestroy()
}
private inner class PlayServiceConnection : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
playService = (service as PlayService.PlayBinder).service
}
override fun onServiceDisconnected(name: ComponentName) {
Log.e(javaClass.simpleName, "service disconnected")
}
}
private fun showEnsureDialog() {
secretDialog = SecretDialog(this, object : OnSecretDialogListener {
override fun onCancel() {
secretDialog!!.dismiss()
// finishAll()
// Process.killProcess(Process.myPid())
// System.exit(0)
}
override fun onSure() {
secretDialog!!.dismiss()
}
})
secretDialog!!.setCanceledOnTouchOutside(false)
secretDialog!!.show()
}
private lateinit var mWindowManager: WindowManager
private var floatRootView: View? = null
......
......@@ -20,7 +20,6 @@ import com.umeng.socialize.UMShareAPI
import com.ydl.component.BuildConfig
import com.ydl.component.MainActivity
import com.ydl.component.R
import com.ydl.media.audio.PlayService
import com.ydl.ydlcommon.actions.crash.Cockroach
import com.ydl.ydlcommon.actions.crash.ExceptionHandler
import com.ydl.ydlcommon.base.config.HttpConfig
......@@ -78,15 +77,6 @@ class DemoAppLifecycles : IAppLifecycles {
// YDLCommonPlugin plugin = new YDLCommonPlugin();
// flutterEngine.getLocalizationChannel().channel.setMethodCallHandler(plugin);
val intent = Intent(application, PlayService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
application.startForegroundService(intent)
}else{
application.startService(intent)
}
// application.registerActivityLifecycleCallbacks(new CoursePlayLifecycle());
}
}
......
......@@ -4,8 +4,6 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application>
<service android:name=".audio.PlayService" />
<receiver android:name=".audio.receiver.RemoteControlReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
......
package com.ydl.media.audio
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.Build
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import com.ydl.media.audio.constants.Extras
import com.ydl.media.audio.manager.MediaSessionManager
import com.ydl.media.audio.manager.NotifyManager
/**
* Created by haorui on 2019-10-27 .
* Des: 音乐播放后台服务
*/
class PlayService : Service() {
inner class PlayBinder : Binder() {
val service: PlayService
get() = this@PlayService
}
override fun onCreate() {
super.onCreate()
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
var nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager;
//数字是随便写的“40”,
nm.createNotificationChannel( NotificationChannel("40", "App Service", NotificationManager.IMPORTANCE_DEFAULT));
var builder = NotificationCompat.Builder(this, "40");
//其中的2,是也随便写的,正式项目也是随便写
startForeground(2 ,builder.build());
}
Log.i(TAG, "onCreate: " + javaClass.simpleName)
AudioPlayer.get().init(this)
MediaSessionManager.get().init(this)
NotifyManager.get().init(this)
}
override fun onBind(intent: Intent): IBinder? {
return PlayBinder()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent != null && intent.action != null) {
when (intent.action) {
Extras.ACTION_STOP -> stop()
}
}
return Service.START_NOT_STICKY
}
private fun stop() {
AudioPlayer.get().stopPlayer()
NotifyManager.get().cancelAll()
}
companion object {
private val TAG = "Service"
fun startCommand(context: Context, action: String) {
val intent = Intent(context, PlayService::class.java)
intent.action = action
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent)
}else{
context.startService(intent)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment