Skip to content

Commit fb24f42

Browse files
committed
Fatal Exception: java.lang.NullPointerException
Attempt to invoke interface method 'android.media.session.ISessionController android.media.session.ISession.getController()' on a null object reference
1 parent c2a90f5 commit fb24f42

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ android {
4141
else -> 0
4242
}
4343

44-
val vCode = 433
44+
val vCode = 436
4545
versionCode = vCode - singleAbiNum
46-
versionName = "2.1.16"
46+
versionName = "2.1.17"
4747

4848
ndk {
4949
//noinspection ChromeOsAbiSupport

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181

182182
<service
183183
android:name=".services.PNotificationListenerService"
184-
android:exported="true"
184+
android:exported="false"
185185
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
186186
<intent-filter>
187187
<action android:name="android.service.notification.NotificationListenerService" />

app/src/main/java/com/ismartcoding/plain/services/PNotificationListenerService.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ class PNotificationListenerService : NotificationListenerService() {
129129
LogCat.w("PNotificationListenerService: not connected, ignoring cancel request")
130130
return@receiveEventHandler
131131
}
132+
if (!Permission.NOTIFICATION_LISTENER.can(applicationContext)) {
133+
LogCat.w("PNotificationListenerService: permission not granted, ignoring cancel request")
134+
isConnected = false
135+
return@receiveEventHandler
136+
}
132137

133138
try {
134139
if (event.ids.size == TempData.notifications.size) {
@@ -166,6 +171,11 @@ class PNotificationListenerService : NotificationListenerService() {
166171
} catch (ex: Exception) {
167172
LogCat.e("Error cleaning up events: ${ex.message}")
168173
}
174+
try {
175+
requestRebind(ComponentName(applicationContext, PNotificationListenerService::class.java))
176+
} catch (ex: Exception) {
177+
LogCat.e("Error requesting rebind: ${ex.message}")
178+
}
169179
}
170180

171181
companion object {

app/src/main/java/com/ismartcoding/plain/ui/components/mediaviewer/video/MediaVideo.kt

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxSize
99
import androidx.compose.foundation.layout.size
1010
import androidx.compose.foundation.pager.PagerState
1111
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.DisposableEffect
1213
import androidx.compose.runtime.LaunchedEffect
1314
import androidx.compose.runtime.derivedStateOf
1415
import androidx.compose.runtime.getValue
@@ -65,44 +66,45 @@ fun MediaVideo(
6566
val scope = rememberCoroutineScope()
6667
val viewerAlpha = remember { Animatable(0F) }
6768
val context = LocalContext.current
69+
val appContext = remember(context) { context.applicationContext }
6870

69-
// 容器大小
71+
// Container size
7072
var bSize by remember { mutableStateOf(IntSize(0, 0)) }
71-
// 容器比例
73+
// Container aspect ratio
7274
val bRatio by remember { derivedStateOf { bSize.width.toFloat() / bSize.height.toFloat() } }
73-
// 视频原始大小
75+
// Video intrinsic size
7476
var vSize by remember { mutableStateOf(IntSize(0, 0)) }
75-
// 视频原始比例
77+
// Video intrinsic aspect ratio
7678
val vRatio by remember { derivedStateOf { if (vSize.height == 0) 1f else vSize.width.toFloat() / vSize.height.toFloat() } }
77-
// 是否宽度与容器大小一致
79+
// Whether width matches the container width
7880
var widthFixed by remember { mutableStateOf(false) }
79-
// 长宽是否均超出容器长宽
81+
// Whether both width and height exceed container bounds
8082
val superSize by remember {
8183
derivedStateOf {
8284
vSize.height > bSize.height && vSize.width > bSize.width
8385
}
8486
}
85-
// 显示大小
87+
// Display size
8688
val uSize by remember {
8789
derivedStateOf {
8890
if (vSize == IntSize.Zero || bSize == IntSize.Zero) {
8991
bSize
9092
} else if (vRatio > bRatio) {
91-
// 宽度一致
93+
// Match container width
9294
val uW = bSize.width
9395
val uH = uW / vRatio
9496
widthFixed = true
9597
IntSize(uW, uH.toInt())
9698
} else {
97-
// 高度一致
99+
// Match container height
98100
val uH = bSize.height
99101
val uW = uH * vRatio
100102
widthFixed = false
101103
IntSize(uW.toInt(), uH)
102104
}
103105
}
104106
}
105-
// 视频显示的真实大小
107+
// Actual rendered video size
106108
val rSize by remember {
107109
derivedStateOf {
108110
IntSize(
@@ -135,19 +137,19 @@ fun MediaVideo(
135137
}
136138
}
137139

138-
// 视频是否加载成功
140+
// Whether the video is successfully specified/loaded
139141
var videoSpecified by remember { mutableStateOf(false) }
140142

141-
// 初始化视频尺寸
143+
// Initialize video dimensions
142144
LaunchedEffect(model.path) {
143145
if (model.intrinsicSize == IntSize.Zero) {
144-
// 尝试从不同的数据源获取视频尺寸
146+
// Try to obtain video dimensions from various sources
145147
when (val data = model.data) {
146148
is com.ismartcoding.plain.data.DVideo -> {
147149
model.initAsync(data)
148150
}
149151
else -> {
150-
// 如果没有data,直接使用VideoHelper获取尺寸
152+
// If there is no data, use VideoHelper to get the size directly
151153
val size = com.ismartcoding.plain.helpers.VideoHelper.getIntrinsicSize(model.path)
152154
if (size != IntSize.Zero) {
153155
model.intrinsicSize = size
@@ -198,7 +200,7 @@ fun MediaVideo(
198200
}
199201
videoState.initData(player)
200202
mediaSession?.release()
201-
mediaSession = MediaSession.Builder(context, ForwardingPlayer(player))
203+
mediaSession = MediaSession.Builder(appContext, ForwardingPlayer(player))
202204
.setId("VideoPlayerMediaSession_${UUID.randomUUID().toString().lowercase().split("-").first()}")
203205
.build()
204206
val exoPlayerMediaItems = listOf(
@@ -220,6 +222,13 @@ fun MediaVideo(
220222
player.play()
221223
}
222224

225+
DisposableEffect(Unit) {
226+
onDispose {
227+
mediaSession?.release()
228+
mediaSession = null
229+
}
230+
}
231+
223232
Box(
224233
modifier = modifier
225234
.fillMaxSize()

0 commit comments

Comments
 (0)