forked from recloudstream/cloudstream
update VideoDownloadService (#377)
This commit is contained in:
parent
aacd57cb5d
commit
b6ac155350
1 changed files with 44 additions and 7 deletions
|
@ -1,11 +1,22 @@
|
||||||
package com.lagradost.cloudstream3.services
|
package com.lagradost.cloudstream3.services
|
||||||
|
import android.app.Service
|
||||||
import android.app.IntentService
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.IBinder
|
||||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class VideoDownloadService : IntentService("VideoDownloadService") {
|
class VideoDownloadService : Service() {
|
||||||
override fun onHandleIntent(intent: Intent?) {
|
|
||||||
|
private val downloadScope = CoroutineScope(Dispatchers.Default)
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
val id = intent.getIntExtra("id", -1)
|
val id = intent.getIntExtra("id", -1)
|
||||||
val type = intent.getStringExtra("type")
|
val type = intent.getStringExtra("type")
|
||||||
|
@ -14,10 +25,36 @@ class VideoDownloadService : IntentService("VideoDownloadService") {
|
||||||
"resume" -> VideoDownloadManager.DownloadActionType.Resume
|
"resume" -> VideoDownloadManager.DownloadActionType.Resume
|
||||||
"pause" -> VideoDownloadManager.DownloadActionType.Pause
|
"pause" -> VideoDownloadManager.DownloadActionType.Pause
|
||||||
"stop" -> VideoDownloadManager.DownloadActionType.Stop
|
"stop" -> VideoDownloadManager.DownloadActionType.Stop
|
||||||
else -> return
|
else -> return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadScope.launch {
|
||||||
VideoDownloadManager.downloadEvent.invoke(Pair(id, state))
|
VideoDownloadManager.downloadEvent.invoke(Pair(id, state))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
downloadScope.coroutineContext.cancel()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// override fun onHandleIntent(intent: Intent?) {
|
||||||
|
// if (intent != null) {
|
||||||
|
// val id = intent.getIntExtra("id", -1)
|
||||||
|
// val type = intent.getStringExtra("type")
|
||||||
|
// if (id != -1 && type != null) {
|
||||||
|
// val state = when (type) {
|
||||||
|
// "resume" -> VideoDownloadManager.DownloadActionType.Resume
|
||||||
|
// "pause" -> VideoDownloadManager.DownloadActionType.Pause
|
||||||
|
// "stop" -> VideoDownloadManager.DownloadActionType.Stop
|
||||||
|
// else -> return
|
||||||
|
// }
|
||||||
|
// VideoDownloadManager.downloadEvent.invoke(Pair(id, state))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
Loading…
Reference in a new issue