expo-libvlc-player 3.4.3 → 3.4.5

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.
@@ -1,7 +1,7 @@
1
1
  apply plugin: "com.android.library"
2
2
 
3
3
  group = "expo.modules.libvlcplayer"
4
- version = "3.4.3"
4
+ version = "3.4.5"
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -27,7 +27,7 @@ android {
27
27
  namespace "expo.modules.libvlcplayer"
28
28
  defaultConfig {
29
29
  versionCode 1
30
- versionName "3.4.3"
30
+ versionName "3.4.5"
31
31
  consumerProguardFiles("proguard-rules.pro")
32
32
  }
33
33
  lintOptions {
@@ -60,7 +60,7 @@ class LibVlcPlayerView(
60
60
  private var media: Media? = null
61
61
  var vlcDialog: VLCDialog? = null
62
62
 
63
- var mediaLength: Long = 0L
63
+ var mediaLength: Long? = null
64
64
 
65
65
  private var shouldCreate: Boolean = false
66
66
  var firstPlay: Boolean = false
@@ -203,58 +203,60 @@ class LibVlcPlayerView(
203
203
  }
204
204
 
205
205
  fun setContentFit() {
206
- mediaPlayer?.let { player ->
207
- val textureView = getTextureView() ?: return
206
+ post {
207
+ mediaPlayer?.let { player ->
208
+ val textureView = getTextureView() ?: return@post
208
209
 
209
- val video = player.getCurrentVideoTrack()
210
+ val video = player.getCurrentVideoTrack()
210
211
 
211
- val matrix = Matrix()
212
+ val matrix = Matrix()
212
213
 
213
- if (video != null) {
214
- val viewWidth = playerView.width.toFloat()
215
- val viewHeight = playerView.height.toFloat()
214
+ if (video != null) {
215
+ val viewWidth = playerView.width.toFloat()
216
+ val viewHeight = playerView.height.toFloat()
216
217
 
217
- val videoWidth = video.width.toFloat()
218
- val videoHeight = video.height.toFloat()
218
+ val videoWidth = video.width.toFloat()
219
+ val videoHeight = video.height.toFloat()
219
220
 
220
- val viewAspect = viewWidth / viewHeight
221
- val videoAspect = videoWidth / videoHeight
221
+ val viewAspect = viewWidth / viewHeight
222
+ val videoAspect = videoWidth / videoHeight
222
223
 
223
- val pivotX = viewWidth / 2f
224
- val pivotY = viewHeight / 2f
224
+ val pivotX = viewWidth / 2f
225
+ val pivotY = viewHeight / 2f
225
226
 
226
- when (contentFit) {
227
- VideoContentFit.CONTAIN -> {
228
- // No scale required
229
- }
227
+ when (contentFit) {
228
+ VideoContentFit.CONTAIN -> {
229
+ // No scale required
230
+ }
231
+
232
+ VideoContentFit.COVER -> {
233
+ val scale =
234
+ if (videoAspect > viewAspect) {
235
+ videoAspect / viewAspect
236
+ } else {
237
+ viewAspect / videoAspect
238
+ }
239
+
240
+ matrix.setScale(scale, scale, pivotX, pivotY)
241
+ }
242
+
243
+ VideoContentFit.FILL -> {
244
+ var scaleX = 1f
245
+ var scaleY = 1f
230
246
 
231
- VideoContentFit.COVER -> {
232
- val scale =
233
247
  if (videoAspect > viewAspect) {
234
- videoAspect / viewAspect
248
+ scaleY = videoAspect / viewAspect
235
249
  } else {
236
- viewAspect / videoAspect
250
+ scaleX = viewAspect / videoAspect
237
251
  }
238
252
 
239
- matrix.setScale(scale, scale, pivotX, pivotY)
240
- }
241
-
242
- VideoContentFit.FILL -> {
243
- var scaleX = 1f
244
- var scaleY = 1f
245
-
246
- if (videoAspect > viewAspect) {
247
- scaleY = videoAspect / viewAspect
248
- } else {
249
- scaleX = viewAspect / videoAspect
253
+ matrix.setScale(scaleX, scaleY, pivotX, pivotY)
250
254
  }
251
-
252
- matrix.setScale(scaleX, scaleY, pivotX, pivotY)
253
255
  }
254
256
  }
255
- }
256
257
 
257
- textureView.setTransform(matrix)
258
+ textureView.setTransform(matrix)
259
+ }
258
260
  }
259
261
  }
260
262
 
@@ -321,7 +323,12 @@ class LibVlcPlayerView(
321
323
  tracks = mediaTracks,
322
324
  )
323
325
 
324
- mediaLength = length
326
+ mediaLength =
327
+ if (length > 0L) {
328
+ length
329
+ } else {
330
+ null
331
+ }
325
332
  }
326
333
 
327
334
  return mediaInfo
@@ -398,10 +405,7 @@ class LibVlcPlayerView(
398
405
  var aspectRatio: String? = null
399
406
  set(value) {
400
407
  field = value
401
-
402
- post {
403
- setContentFit()
404
- }
408
+ setContentFit()
405
409
  }
406
410
 
407
411
  var contentFit: VideoContentFit = VideoContentFit.CONTAIN
@@ -515,7 +519,8 @@ class LibVlcPlayerView(
515
519
  }
516
520
  } else {
517
521
  if (type == "position") {
518
- time = (value * mediaLength.toDouble()).toInt()
522
+ val length = mediaLength ?: 0L
523
+ time = (value * length.toDouble()).toInt()
519
524
  } else {
520
525
  time = value.toInt()
521
526
  }
@@ -75,7 +75,7 @@ fun LibVlcPlayerView.setMediaPlayerListener() {
75
75
  onTimeChanged(mapOf("time" to player.getTime().toInt()))
76
76
 
77
77
  if (firstTime) {
78
- if (mediaLength == 0L) {
78
+ if (mediaLength == null) {
79
79
  onFirstPlay(getMediaInfo())
80
80
  }
81
81
 
@@ -23,7 +23,7 @@ class LibVlcPlayerView: ExpoView {
23
23
  var vlcDialog: VLCDialogProvider?
24
24
  var vlcDialogRef: NSValue?
25
25
 
26
- var mediaLength: Int32 = 0
26
+ var mediaLength: Int32?
27
27
  private var oldVolume: Int = maxPlayerVolume
28
28
 
29
29
  private var shouldCreate: Bool = false
@@ -143,42 +143,44 @@ class LibVlcPlayerView: ExpoView {
143
143
  }
144
144
 
145
145
  func setContentFit() {
146
- if let player = mediaPlayer {
147
- let view = playerView.frame.size
148
-
149
- let video = player.videoSize
150
-
151
- var transform: CGAffineTransform = .identity
152
-
153
- if video != .zero {
154
- let viewAspect = view.width / view.height
155
- let videoAspect = video.width / video.height
156
-
157
- switch contentFit {
158
- case .contain:
159
- // No transform required
160
- break
161
- case .cover:
162
- let scale = videoAspect > viewAspect ?
163
- videoAspect / viewAspect :
164
- viewAspect / videoAspect
165
-
166
- transform = CGAffineTransform(scaleX: scale, y: scale)
167
- case .fill:
168
- var scaleX = 1.0
169
- var scaleY = 1.0
170
-
171
- if videoAspect > viewAspect {
172
- scaleY = videoAspect / viewAspect
173
- } else {
174
- scaleX = viewAspect / videoAspect
146
+ DispatchQueue.main.async {
147
+ if let player = self.mediaPlayer {
148
+ let view = self.playerView.frame.size
149
+
150
+ let video = player.videoSize
151
+
152
+ var transform: CGAffineTransform = .identity
153
+
154
+ if video != .zero {
155
+ let viewAspect = view.width / view.height
156
+ let videoAspect = video.width / video.height
157
+
158
+ switch self.contentFit {
159
+ case .contain:
160
+ // No transform required
161
+ break
162
+ case .cover:
163
+ let scale = videoAspect > viewAspect ?
164
+ videoAspect / viewAspect :
165
+ viewAspect / videoAspect
166
+
167
+ transform = CGAffineTransform(scaleX: scale, y: scale)
168
+ case .fill:
169
+ var scaleX = 1.0
170
+ var scaleY = 1.0
171
+
172
+ if videoAspect > viewAspect {
173
+ scaleY = videoAspect / viewAspect
174
+ } else {
175
+ scaleX = viewAspect / videoAspect
176
+ }
177
+
178
+ transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
175
179
  }
176
-
177
- transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
178
180
  }
179
- }
180
181
 
181
- playerView.transform = transform
182
+ self.playerView.transform = transform
183
+ }
182
184
  }
183
185
  }
184
186
 
@@ -246,7 +248,9 @@ class LibVlcPlayerView: ExpoView {
246
248
  tracks: mediaTracks,
247
249
  )
248
250
 
249
- mediaLength = length
251
+ mediaLength = length > 0 ?
252
+ length :
253
+ nil
250
254
  }
251
255
 
252
256
  return mediaInfo
@@ -325,9 +329,7 @@ class LibVlcPlayerView: ExpoView {
325
329
 
326
330
  var aspectRatio: String? {
327
331
  didSet {
328
- DispatchQueue.main.async {
329
- self.setContentFit()
330
- }
332
+ setContentFit()
331
333
  }
332
334
  }
333
335
 
@@ -428,7 +430,8 @@ class LibVlcPlayerView: ExpoView {
428
430
  }
429
431
  } else {
430
432
  if type == "position" {
431
- time = Int(value * Double(mediaLength))
433
+ let length = mediaLength ?? 0
434
+ time = Int(value * Double(length))
432
435
  } else {
433
436
  time = Int(value)
434
437
  }
@@ -67,7 +67,7 @@ extension LibVlcPlayerView: VLCMediaPlayerDelegate {
67
67
  onTimeChanged(["time": player.time.intValue])
68
68
 
69
69
  if firstTime {
70
- if mediaLength == 0 {
70
+ if mediaLength == nil {
71
71
  onFirstPlay(getMediaInfo())
72
72
  }
73
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-libvlc-player",
3
- "version": "3.4.3",
3
+ "version": "3.4.5",
4
4
  "description": "LibVLC Player for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",