@@ -142,20 +142,26 @@ class CustomNotification constructor(
142142 notificationManager.cancelAll()
143143 }
144144
145- override fun onPlaybackStateChanged (songInfo : SongInfo ? , state : String ,
146- hasNextSong : Boolean , hasPreSong : Boolean ) {
145+ override fun onPlaybackStateChanged (
146+ songInfo : SongInfo ? , state : String ,
147+ hasNextSong : Boolean , hasPreSong : Boolean
148+ ) {
147149 this .hasNextSong = hasNextSong
148150 this .hasPreSong = hasPreSong
149151 playbackState = state
150152 this .songInfo = songInfo
151153 when (state) {
152154 PlaybackStage .PLAYING -> {
153- timerTaskManager?.startToUpdateProgress()
155+ if (ID_PROGRESSBAR .getResId() != 0 ) {
156+ timerTaskManager?.startToUpdateProgress()
157+ }
154158 }
155159 PlaybackStage .PAUSE ,
156160 PlaybackStage .ERROR ,
157161 PlaybackStage .IDLE -> {
158- timerTaskManager?.stopToUpdateProgress()
162+ if (ID_PROGRESSBAR .getResId() != 0 ) {
163+ timerTaskManager?.stopToUpdateProgress()
164+ }
159165 }
160166 }
161167 if (state == PlaybackStage .IDLE ) {
@@ -319,14 +325,20 @@ class CustomNotification constructor(
319325 bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_PLAY_OR_PAUSE .getResId(), name.getResDrawable())
320326 }
321327 // 设置喜欢或收藏按钮
322- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_FAVORITE .getResId(),
323- isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_FAVORITE , DRAWABLE_NOTIFY_BTN_LIGHT_FAVORITE ))
328+ bigRemoteView?.setImageViewResource(
329+ ID_IMG_NOTIFY_FAVORITE .getResId(),
330+ isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_FAVORITE , DRAWABLE_NOTIFY_BTN_LIGHT_FAVORITE )
331+ )
324332 // 设置歌词按钮
325- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_LYRICS .getResId(),
326- isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_LYRICS , DRAWABLE_NOTIFY_BTN_LIGHT_LYRICS ))
333+ bigRemoteView?.setImageViewResource(
334+ ID_IMG_NOTIFY_LYRICS .getResId(),
335+ isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_LYRICS , DRAWABLE_NOTIFY_BTN_LIGHT_LYRICS )
336+ )
327337 // 设置下载按钮
328- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_DOWNLOAD .getResId(),
329- isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_DOWNLOAD , DRAWABLE_NOTIFY_BTN_LIGHT_DOWNLOAD ))
338+ bigRemoteView?.setImageViewResource(
339+ ID_IMG_NOTIFY_DOWNLOAD .getResId(),
340+ isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_DOWNLOAD , DRAWABLE_NOTIFY_BTN_LIGHT_DOWNLOAD )
341+ )
330342 // 上一首下一首按钮
331343 disableNextBtn(hasNextSong, isDark)
332344 disablePreviousBtn(hasPreSong, isDark)
@@ -418,7 +430,7 @@ class CustomNotification constructor(
418430 mStarted = true
419431 }
420432 }
421- if (timerTaskManager == null ) {
433+ if (timerTaskManager == null && ID_PROGRESSBAR .getResId() != 0 ) {
422434 timerTaskManager = TimerTaskManager ()
423435 timerTaskManager?.setUpdateProgressTask {
424436 val player = (context as MusicService ).binder?.player
@@ -434,7 +446,7 @@ class CustomNotification constructor(
434446 }
435447 }
436448 val player = (context as MusicService ).binder?.player
437- if (player?.isPlaying() == true && timerTaskManager?.isRunning() == false ) {
449+ if (player?.isPlaying() == true && timerTaskManager?.isRunning() == false && ID_PROGRESSBAR .getResId() != 0 ) {
438450 timerTaskManager?.startToUpdateProgress()
439451 }
440452 }
@@ -450,8 +462,10 @@ class CustomNotification constructor(
450462 }
451463 (context as MusicService ).stopForeground(true )
452464 }
453- timerTaskManager?.removeUpdateProgressTask()
454- timerTaskManager = null
465+ if (ID_PROGRESSBAR .getResId() != 0 ) {
466+ timerTaskManager?.removeUpdateProgressTask()
467+ timerTaskManager = null
468+ }
455469 }
456470
457471 override fun onCommand (command : String? , extras : Bundle ? ) {
@@ -477,12 +491,16 @@ class CustomNotification constructor(
477491 val isDark = colorUtils.isDarkNotificationBar(context, mNotification!! )
478492 // 喜欢或收藏按钮选中时样式
479493 if (isFavorite) {
480- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_FAVORITE .getResId(),
481- DRAWABLE_NOTIFY_BTN_FAVORITE .getResDrawable())
494+ bigRemoteView?.setImageViewResource(
495+ ID_IMG_NOTIFY_FAVORITE .getResId(),
496+ DRAWABLE_NOTIFY_BTN_FAVORITE .getResDrawable()
497+ )
482498 } else {
483499 // 喜欢或收藏按钮没选中时样式
484- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_FAVORITE .getResId(),
485- isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_FAVORITE , DRAWABLE_NOTIFY_BTN_LIGHT_FAVORITE ))
500+ bigRemoteView?.setImageViewResource(
501+ ID_IMG_NOTIFY_FAVORITE .getResId(),
502+ isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_FAVORITE , DRAWABLE_NOTIFY_BTN_LIGHT_FAVORITE )
503+ )
486504 }
487505 if (mNotification != null ) {
488506 notificationManager?.notify(NOTIFICATION_ID , mNotification)
@@ -499,12 +517,16 @@ class CustomNotification constructor(
499517 val isDark = colorUtils.isDarkNotificationBar(context, mNotification!! )
500518 // 歌词按钮选中时样式
501519 if (isChecked) {
502- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_LYRICS .getResId(),
503- DRAWABLE_NOTIFY_BTN_LYRICS .getResDrawable())
520+ bigRemoteView?.setImageViewResource(
521+ ID_IMG_NOTIFY_LYRICS .getResId(),
522+ DRAWABLE_NOTIFY_BTN_LYRICS .getResDrawable()
523+ )
504524 } else {
505525 // 歌词按钮没选中时样式
506- bigRemoteView?.setImageViewResource(ID_IMG_NOTIFY_LYRICS .getResId(),
507- isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_LYRICS , DRAWABLE_NOTIFY_BTN_LIGHT_LYRICS ))
526+ bigRemoteView?.setImageViewResource(
527+ ID_IMG_NOTIFY_LYRICS .getResId(),
528+ isDark.getResDrawableByDark(DRAWABLE_NOTIFY_BTN_DARK_LYRICS , DRAWABLE_NOTIFY_BTN_LIGHT_LYRICS )
529+ )
508530 }
509531 if (mNotification != null ) {
510532 notificationManager?.notify(NOTIFICATION_ID , mNotification)
0 commit comments