gpt4 book ai didi

android - 听 onDownloadComplete Exoplayer

转载 作者:行者123 更新时间:2023-12-02 13:30:32 67 4
gpt4 key购买 nike

我正在尝试下载视频以在 exoplayer 中离线播放,但我不知道如何收听 onDownloadComplete。在 exoplayer 文档中,他们说 DownloadService是一个环绕 android DownloadManager所以我试着听 DownloadManager.ACTION_DOWNLOAD_COMPLETE广播但它不起作用,实际上这是我第一次使用 exoplayer。

下载服务

class MediaDownloadService : DownloadService(
C.DOWNLOAD_NOTIFICATION_ID, DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL,
C.CHANNEL_ID, R.string.channel_name, R.string.channel_description
) {
override fun onCreate() {
registerReceiver(onComplete, IntentFilter(ACTION_DOWNLOAD_COMPLETE))
super.onCreate()
}

override fun onDestroy() {
unregisterReceiver(onComplete)
super.onDestroy()
}

override fun getDownloadManager(): DownloadManager {
return DownloadUtil.getDownloadManager(this)
}

override fun getForegroundNotification(downloads: MutableList<Download>): Notification {
val intent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val notificationHelper = DownloadNotificationHelper(this, C.CHANNEL_ID)

return notificationHelper.buildProgressNotification(
R.drawable.ic_notification,
pendingIntent,
"simple message",
downloads
)
}

override fun getScheduler(): Scheduler? {
return null
}


val onComplete: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(ctxt: Context?, intent: Intent?) {
toast("Download COmpleted")
}
}
}

最佳答案

您可以比较bytesDownloadedcontentLength检查它是否完成下载。

downloadManager.addListener(object : DownloadManager.Listener {
override fun onDownloadChanged(downloadManager: DownloadManager, download: Download) {
if (download.bytesDownloaded == download.contentLength) {
Log.d("Completed")
}
}
})

关于android - 听 onDownloadComplete Exoplayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61827058/

67 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com