react-native-media-notification 0.4.0-beta.0 → 0.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ class AudioFocusListener(
27
27
  if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
28
28
  abandonAudioFocus()
29
29
  mPlayOnAudioFocus = false
30
- player.sendEvent(Controls.STOP, null)
30
+ player.sendEvent(Controls.PAUSE, null)
31
31
  } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
32
32
  Handler(player.applicationLooper).post {
33
33
  if (player.isPlaying) {
@@ -9,7 +9,6 @@ import android.os.Binder
9
9
  import android.os.Build
10
10
  import android.os.Bundle
11
11
  import android.os.IBinder
12
- import android.util.Log
13
12
  import androidx.annotation.RequiresApi
14
13
  import androidx.media3.common.MediaItem
15
14
  import androidx.media3.common.Player
@@ -290,6 +289,18 @@ class MediaControlsService : MediaLibraryService() {
290
289
  )
291
290
  }
292
291
 
292
+ override fun onSearch(
293
+ session: MediaLibrarySession,
294
+ browser: MediaSession.ControllerInfo,
295
+ query: String,
296
+ params: LibraryParams?
297
+ ): ListenableFuture<LibraryResult<Void>> {
298
+ session.notifySearchResultChanged(browser, query, MediaStore.Instance.searchCount(query), params)
299
+ return Futures.immediateFuture(
300
+ LibraryResult.ofVoid()
301
+ )
302
+ }
303
+
293
304
  override fun onPlaybackResumption(
294
305
  mediaSession: MediaSession,
295
306
  controller: MediaSession.ControllerInfo
@@ -115,14 +115,26 @@ class MediaStore {
115
115
  )
116
116
  }
117
117
 
118
+ private fun buildWordList(query: String): List<String> {
119
+ return query.split(" ").map { it.trim().lowercase() }.filter { it.length > 1 }
120
+ }
121
+
118
122
  fun search(query: String, page: Int, pageSize: Int): LibraryResult<ImmutableList<MediaItem>>? {
119
123
  if (mediaItemsHierarchy == null) return null
120
- val words = query.split(" ").map { it.trim().lowercase() }.filter { it.length > 1 }
124
+ val words = this.buildWordList(query)
121
125
 
122
126
  val results = searchElements(mediaItemsHierarchy!!, words)
123
127
  return LibraryResult.ofItemList(results.paginate(page, pageSize).map { buildMediaItem(it) }, null)
124
128
  }
125
129
 
130
+ fun searchCount(query: String): Int {
131
+ if (mediaItemsHierarchy == null) return 0
132
+ val words = this.buildWordList(query)
133
+
134
+ val results = searchElements(mediaItemsHierarchy!!, words)
135
+ return results.size
136
+ }
137
+
126
138
  @OptIn(UnstableApi::class)
127
139
  fun getLastMediaItem(): MediaSession.MediaItemsWithStartPosition {
128
140
  if (sharedPrefs == null || mediaItemsHierarchy == null) return MediaSession.MediaItemsWithStartPosition(emptyList(), 0, 0)
@@ -146,7 +158,7 @@ class MediaStore {
146
158
  results.add(element)
147
159
  }
148
160
  element.items?.forEach { child ->
149
- searchElements(child, words)
161
+ searchElements(child, words).forEach { results.add(it) }
150
162
  }
151
163
 
152
164
  return results
@@ -156,11 +168,11 @@ class MediaStore {
156
168
  val searchText = (element.title ?: "") + " " + (element.artist ?: "") + " " + (element.album ?: "")
157
169
  val lowerSearchText = searchText.lowercase()
158
170
  for (word in words) {
159
- if (!lowerSearchText.contains(word)) {
160
- return false
171
+ if (lowerSearchText.contains(word)) {
172
+ return true
161
173
  }
162
174
  }
163
- return true
175
+ return false
164
176
  }
165
177
 
166
178
  inline fun MediaItem.Builder.setMediaMetadata(element: MediaElement): MediaItem.Builder {
package/package.json CHANGED
@@ -1,169 +1,169 @@
1
- {
2
- "name": "react-native-media-notification",
3
- "version": "0.4.0-beta.0",
4
- "description": "Display and manage media style notifications based on react-native-music-control",
5
- "main": "./lib/module/index.js",
6
- "types": "./lib/typescript/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "source": "./src/index.tsx",
10
- "types": "./lib/typescript/src/index.d.ts",
11
- "default": "./lib/module/index.js"
12
- },
13
- "./package.json": "./package.json"
14
- },
15
- "files": [
16
- "src",
17
- "lib",
18
- "android",
19
- "ios",
20
- "cpp",
21
- "*.podspec",
22
- "react-native.config.js",
23
- "!ios/build",
24
- "!android/build",
25
- "!android/gradle",
26
- "!android/gradlew",
27
- "!android/gradlew.bat",
28
- "!android/local.properties",
29
- "!**/__tests__",
30
- "!**/__fixtures__",
31
- "!**/__mocks__",
32
- "!**/.*"
33
- ],
34
- "scripts": {
35
- "example": "yarn workspace react-native-media-notification-example",
36
- "test": "jest",
37
- "typecheck": "tsc",
38
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
- "prepare": "bob build",
41
- "release": "dotenv release-it --only-version"
42
- },
43
- "keywords": [
44
- "react-native",
45
- "ios",
46
- "android"
47
- ],
48
- "repository": {
49
- "type": "git",
50
- "url": "git+https://github.com/mbpictures/react-native-media-notification.git"
51
- },
52
- "author": "Marius Butz <mbpictures13@gmail.com> (https://github.com/mbpictures)",
53
- "license": "MIT",
54
- "bugs": {
55
- "url": "https://github.com/mbpictures/react-native-media-notification/issues"
56
- },
57
- "homepage": "https://github.com/mbpictures/react-native-media-notification#readme",
58
- "publishConfig": {
59
- "registry": "https://registry.npmjs.org/"
60
- },
61
- "dependencies": {
62
- "fbemitter": "^3.0.0"
63
- },
64
- "devDependencies": {
65
- "@commitlint/config-conventional": "^19.6.0",
66
- "@eslint/compat": "^1.2.7",
67
- "@eslint/eslintrc": "^3.3.0",
68
- "@eslint/js": "^9.22.0",
69
- "@evilmartians/lefthook": "^1.5.0",
70
- "@react-native-community/cli": "15.0.0-alpha.2",
71
- "@react-native/babel-preset": "0.79.2",
72
- "@react-native/eslint-config": "^0.78.0",
73
- "@release-it/conventional-changelog": "^9.0.2",
74
- "@types/fbemitter": "^2.0.35",
75
- "@types/jest": "^29.5.5",
76
- "@types/react": "^19.0.0",
77
- "commitlint": "^19.6.1",
78
- "del-cli": "^5.1.0",
79
- "dotenv-cli": "^10.0.0",
80
- "eslint": "^9.22.0",
81
- "eslint-config-prettier": "^10.1.1",
82
- "eslint-plugin-prettier": "^5.2.3",
83
- "jest": "^29.7.0",
84
- "prettier": "^3.0.3",
85
- "react": "19.0.0",
86
- "react-native": "0.79.2",
87
- "react-native-builder-bob": "^0.40.13",
88
- "release-it": "^19.0.4",
89
- "turbo": "^1.10.7",
90
- "typescript": "^5.8.3"
91
- },
92
- "peerDependencies": {
93
- "react": "*",
94
- "react-native": "*"
95
- },
96
- "workspaces": [
97
- "example"
98
- ],
99
- "packageManager": "yarn@3.6.1",
100
- "jest": {
101
- "preset": "react-native",
102
- "modulePathIgnorePatterns": [
103
- "<rootDir>/example/node_modules",
104
- "<rootDir>/lib/"
105
- ]
106
- },
107
- "commitlint": {
108
- "extends": [
109
- "@commitlint/config-conventional"
110
- ]
111
- },
112
- "release-it": {
113
- "git": {
114
- "commitMessage": "chore: release ${version}",
115
- "tagName": "v${version}"
116
- },
117
- "npm": {
118
- "publish": true
119
- },
120
- "github": {
121
- "release": true
122
- },
123
- "plugins": {
124
- "@release-it/conventional-changelog": {
125
- "preset": {
126
- "name": "angular"
127
- }
128
- }
129
- }
130
- },
131
- "prettier": {
132
- "quoteProps": "consistent",
133
- "singleQuote": true,
134
- "tabWidth": 2,
135
- "trailingComma": "es5",
136
- "useTabs": false
137
- },
138
- "react-native-builder-bob": {
139
- "source": "src",
140
- "output": "lib",
141
- "targets": [
142
- [
143
- "module",
144
- {
145
- "esm": true
146
- }
147
- ],
148
- [
149
- "typescript",
150
- {
151
- "project": "tsconfig.build.json"
152
- }
153
- ]
154
- ]
155
- },
156
- "codegenConfig": {
157
- "name": "MediaControlsSpec",
158
- "type": "modules",
159
- "jsSrcsDir": "src",
160
- "android": {
161
- "javaPackageName": "com.mediacontrols"
162
- }
163
- },
164
- "create-react-native-library": {
165
- "languages": "kotlin-objc",
166
- "type": "turbo-module",
167
- "version": "0.52.0"
168
- }
169
- }
1
+ {
2
+ "name": "react-native-media-notification",
3
+ "version": "0.4.0-beta.2",
4
+ "description": "Display and manage media style notifications based on react-native-music-control",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace react-native-media-notification-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
+ "prepare": "bob build",
41
+ "release": "dotenv release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/mbpictures/react-native-media-notification.git"
51
+ },
52
+ "author": "Marius Butz <mbpictures13@gmail.com> (https://github.com/mbpictures)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/mbpictures/react-native-media-notification/issues"
56
+ },
57
+ "homepage": "https://github.com/mbpictures/react-native-media-notification#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "dependencies": {
62
+ "fbemitter": "^3.0.0"
63
+ },
64
+ "devDependencies": {
65
+ "@commitlint/config-conventional": "^19.6.0",
66
+ "@eslint/compat": "^1.2.7",
67
+ "@eslint/eslintrc": "^3.3.0",
68
+ "@eslint/js": "^9.22.0",
69
+ "@evilmartians/lefthook": "^1.5.0",
70
+ "@react-native-community/cli": "15.0.0-alpha.2",
71
+ "@react-native/babel-preset": "0.79.2",
72
+ "@react-native/eslint-config": "^0.78.0",
73
+ "@release-it/conventional-changelog": "^8.0.2",
74
+ "@types/fbemitter": "^2.0.35",
75
+ "@types/jest": "^29.5.5",
76
+ "@types/react": "^19.0.0",
77
+ "commitlint": "^19.6.1",
78
+ "del-cli": "^5.1.0",
79
+ "dotenv-cli": "^10.0.0",
80
+ "eslint": "^9.22.0",
81
+ "eslint-config-prettier": "^10.1.1",
82
+ "eslint-plugin-prettier": "^5.2.3",
83
+ "jest": "^29.7.0",
84
+ "prettier": "^3.0.3",
85
+ "react": "19.0.0",
86
+ "react-native": "0.79.2",
87
+ "react-native-builder-bob": "^0.40.13",
88
+ "release-it": "^19.0.4",
89
+ "turbo": "^1.10.7",
90
+ "typescript": "^5.8.3"
91
+ },
92
+ "peerDependencies": {
93
+ "react": "*",
94
+ "react-native": "*"
95
+ },
96
+ "workspaces": [
97
+ "example"
98
+ ],
99
+ "packageManager": "yarn@3.6.1",
100
+ "jest": {
101
+ "preset": "react-native",
102
+ "modulePathIgnorePatterns": [
103
+ "<rootDir>/example/node_modules",
104
+ "<rootDir>/lib/"
105
+ ]
106
+ },
107
+ "commitlint": {
108
+ "extends": [
109
+ "@commitlint/config-conventional"
110
+ ]
111
+ },
112
+ "release-it": {
113
+ "git": {
114
+ "commitMessage": "chore: release ${version}",
115
+ "tagName": "v${version}"
116
+ },
117
+ "npm": {
118
+ "publish": true
119
+ },
120
+ "github": {
121
+ "release": true
122
+ },
123
+ "plugins": {
124
+ "@release-it/conventional-changelog": {
125
+ "preset": {
126
+ "name": "angular"
127
+ }
128
+ }
129
+ }
130
+ },
131
+ "prettier": {
132
+ "quoteProps": "consistent",
133
+ "singleQuote": true,
134
+ "tabWidth": 2,
135
+ "trailingComma": "es5",
136
+ "useTabs": false
137
+ },
138
+ "react-native-builder-bob": {
139
+ "source": "src",
140
+ "output": "lib",
141
+ "targets": [
142
+ [
143
+ "module",
144
+ {
145
+ "esm": true
146
+ }
147
+ ],
148
+ [
149
+ "typescript",
150
+ {
151
+ "project": "tsconfig.build.json"
152
+ }
153
+ ]
154
+ ]
155
+ },
156
+ "codegenConfig": {
157
+ "name": "MediaControlsSpec",
158
+ "type": "modules",
159
+ "jsSrcsDir": "src",
160
+ "android": {
161
+ "javaPackageName": "com.mediacontrols"
162
+ }
163
+ },
164
+ "create-react-native-library": {
165
+ "languages": "kotlin-objc",
166
+ "type": "turbo-module",
167
+ "version": "0.52.0"
168
+ }
169
+ }