使用过程遇到一些问题修改,大佬可以批阅下
lewic1987 opened this issue · 2 comments
一、StarrySky类修改
1.修改registerComponentsAndStart方法,修复自定义图片加载器无效问题
修改前:
bridge?.register?.imageLoader = imageLoader
修改后:
bridge?.register?.imageLoader = config.imageLoader
2.修改with方法:去除抛异常,防止线上崩溃率增高,改为返回null的话,外部调用需要判空麻烦一些,这种情况理论上出现很少,增加空实现,外部使用不变
if (bridge == null || bridge?.playerControl == null) {
修改后:
return DefaultPlayerControlImpl()
修改前:
throw NullPointerException("请确保 with 方法在服务连接成功后调用")
}
二、CustomNotification类修改
1.防止通知栏位置来回变化
修改后,并且代码由原来setNotificationPlaybackState方法中移到createNotification方法中:
notificationBuilder.setOngoing(true)
修改前:
builder.setOngoing(playbackState == PlaybackStage.PLAYING)
2.fetchBitmapFromURLAsync方法修改,由于notification每次状态变化都会新建,图片加载是异步的,可能已经不是此notification对象了,所以偶现图片刷新无效问题
修改后:
if (mNotification != null){
notificationManager?.notify(NOTIFICATION_ID, mNotification)
}
修改前:
//notificationManager?.notify(NOTIFICATION_ID, notification)
3.onPlaybackStateChanged方法中stopNotification调用修改,解决歌曲结束时候自动切换下一首时候看到通知栏取消新建的过程
修改后:
if (state == PlaybackStage.STOP) {
stopNotification()
}
修改前:
if (state == PlaybackStage.STOP || state == PlaybackStage.IDEA) {
stopNotification()
}
4.updateRemoteViewUI方法修改:缓存中不切换按钮状态,修复切换歌曲时候有时候按钮状态不对问题
修改后:
if (playbackState == PlaybackStage.PLAYING || playbackState == PlaybackStage.BUFFERING) {
val name =
if (isDark) DRAWABLE_NOTIFY_BTN_DARK_PAUSE_SELECTOR else DRAWABLE_NOTIFY_BTN_LIGHT_PAUSE_SELECTOR
remoteView?.setImageViewResource(ID_IMG_NOTIFY_PLAY_OR_PAUSE.getResId(), name.getResDrawable())
}
修改前:
if (playbackState == PlaybackStage.PLAYING) {
val name =
if (isDark) DRAWABLE_NOTIFY_BTN_DARK_PAUSE_SELECTOR else DRAWABLE_NOTIFY_BTN_LIGHT_PAUSE_SELECTOR
remoteView?.setImageViewResource(ID_IMG_NOTIFY_PLAY_OR_PAUSE.getResId(), name.getResDrawable())
}
5.updateRemoteViewUI方法修改:取消默认图设置,防止来回设置图片闪烁
修改后:
if (art != null) {
remoteView?.setImageViewBitmap(ID_IMG_NOTIFY_ICON.getResId(), art)
bigRemoteView?.setImageViewBitmap(ID_IMG_NOTIFY_ICON.getResId(), art)
}
修改前:
remoteView?.setImageViewBitmap(ID_IMG_NOTIFY_ICON.getResId(), art)
bigRemoteView?.setImageViewBitmap(ID_IMG_NOTIFY_ICON.getResId(), art)
收到
👌