expo-libvlc-player 6.1.13 → 6.1.15
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.
|
@@ -262,7 +262,7 @@ class LibVlcPlayerView(
|
|
|
262
262
|
selectTrack(spuTrack, IMedia.Track.Type.Text)
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
fun addPlayerSlaves() {
|
|
265
|
+
fun addPlayerSlaves(slaves: List<Slave>) {
|
|
266
266
|
slaves.forEach { slave ->
|
|
267
267
|
val source = slave.source
|
|
268
268
|
val type = slave.type
|
|
@@ -290,50 +290,48 @@ class LibVlcPlayerView(
|
|
|
290
290
|
val view = getTextureView(layout) ?: return@post
|
|
291
291
|
val matrix = Matrix()
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
val video = getVideoSize()
|
|
295
|
-
|
|
296
|
-
if (hasVideoSize) {
|
|
297
|
-
val viewWidth = view.width.toFloat()
|
|
298
|
-
val viewHeight = view.height.toFloat()
|
|
299
|
-
|
|
300
|
-
val videoWidth = video.width.toFloat()
|
|
301
|
-
val videoHeight = video.height.toFloat()
|
|
302
|
-
|
|
303
|
-
val viewAspect = viewWidth / viewHeight
|
|
304
|
-
val videoAspect = videoWidth / videoHeight
|
|
293
|
+
val video = getVideoSize()
|
|
305
294
|
|
|
306
|
-
|
|
307
|
-
|
|
295
|
+
if (hasVideoSize) {
|
|
296
|
+
val viewWidth = view.width.toFloat()
|
|
297
|
+
val viewHeight = view.height.toFloat()
|
|
308
298
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// No scale required
|
|
312
|
-
}
|
|
299
|
+
val videoWidth = video.width.toFloat()
|
|
300
|
+
val videoHeight = video.height.toFloat()
|
|
313
301
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (videoAspect > viewAspect) {
|
|
317
|
-
videoAspect / viewAspect
|
|
318
|
-
} else {
|
|
319
|
-
viewAspect / videoAspect
|
|
320
|
-
}
|
|
302
|
+
val viewAspect = viewWidth / viewHeight
|
|
303
|
+
val videoAspect = videoWidth / videoHeight
|
|
321
304
|
|
|
322
|
-
|
|
323
|
-
|
|
305
|
+
val pivotX = viewWidth / 2f
|
|
306
|
+
val pivotY = viewHeight / 2f
|
|
324
307
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
308
|
+
when (contentFit) {
|
|
309
|
+
VideoContentFit.CONTAIN -> {
|
|
310
|
+
// No scale required
|
|
311
|
+
}
|
|
328
312
|
|
|
313
|
+
VideoContentFit.COVER -> {
|
|
314
|
+
val scale =
|
|
329
315
|
if (videoAspect > viewAspect) {
|
|
330
|
-
|
|
316
|
+
videoAspect / viewAspect
|
|
331
317
|
} else {
|
|
332
|
-
|
|
318
|
+
viewAspect / videoAspect
|
|
333
319
|
}
|
|
334
320
|
|
|
335
|
-
|
|
321
|
+
matrix.setScale(scale, scale, pivotX, pivotY)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
VideoContentFit.FILL -> {
|
|
325
|
+
var scaleX = 1f
|
|
326
|
+
var scaleY = 1f
|
|
327
|
+
|
|
328
|
+
if (videoAspect > viewAspect) {
|
|
329
|
+
scaleY = videoAspect / viewAspect
|
|
330
|
+
} else {
|
|
331
|
+
scaleX = viewAspect / videoAspect
|
|
336
332
|
}
|
|
333
|
+
|
|
334
|
+
matrix.setScale(scaleX, scaleY, pivotX, pivotY)
|
|
337
335
|
}
|
|
338
336
|
}
|
|
339
337
|
}
|
|
@@ -345,7 +343,7 @@ class LibVlcPlayerView(
|
|
|
345
343
|
fun setupPlayer() {
|
|
346
344
|
post {
|
|
347
345
|
mediaPlayer?.let { player ->
|
|
348
|
-
addPlayerSlaves()
|
|
346
|
+
addPlayerSlaves(slaves)
|
|
349
347
|
|
|
350
348
|
if (scale != MediaPlayerConstants.DEFAULT_PLAYER_SCALE) {
|
|
351
349
|
player.setScale(scale)
|
|
@@ -417,12 +415,10 @@ class LibVlcPlayerView(
|
|
|
417
415
|
fun getMediaLength(): Long {
|
|
418
416
|
var length: Long = 0L
|
|
419
417
|
|
|
420
|
-
mediaPlayer?.
|
|
421
|
-
val duration = player.getLength()
|
|
418
|
+
val duration = mediaPlayer?.getLength() ?: 0L
|
|
422
419
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
420
|
+
if (duration > 0L) {
|
|
421
|
+
length = duration
|
|
426
422
|
}
|
|
427
423
|
|
|
428
424
|
return length
|
|
@@ -431,19 +427,17 @@ class LibVlcPlayerView(
|
|
|
431
427
|
fun getMediaInfo(): MediaInfo {
|
|
432
428
|
var mediaInfo = MediaInfo()
|
|
433
429
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
)
|
|
446
|
-
}
|
|
430
|
+
val video = getVideoSize()
|
|
431
|
+
val length = getMediaLength()
|
|
432
|
+
val seekable = mediaPlayer?.isSeekable() ?: false
|
|
433
|
+
|
|
434
|
+
mediaInfo =
|
|
435
|
+
MediaInfo(
|
|
436
|
+
width = video.width,
|
|
437
|
+
height = video.height,
|
|
438
|
+
length = length.toDouble(),
|
|
439
|
+
seekable = seekable,
|
|
440
|
+
)
|
|
447
441
|
|
|
448
442
|
return mediaInfo
|
|
449
443
|
}
|
|
@@ -505,7 +499,7 @@ class LibVlcPlayerView(
|
|
|
505
499
|
field = field.apply { addAll(newSlaves) }
|
|
506
500
|
|
|
507
501
|
if (!newSlaves.isEmpty()) {
|
|
508
|
-
addPlayerSlaves()
|
|
502
|
+
addPlayerSlaves(newSlaves)
|
|
509
503
|
}
|
|
510
504
|
}
|
|
511
505
|
|
|
@@ -604,7 +598,10 @@ class LibVlcPlayerView(
|
|
|
604
598
|
|
|
605
599
|
mediaPlayer?.let { player ->
|
|
606
600
|
val shouldPause = condition == true && player.isPlaying()
|
|
607
|
-
|
|
601
|
+
|
|
602
|
+
if (shouldPause) {
|
|
603
|
+
player.pause()
|
|
604
|
+
}
|
|
608
605
|
}
|
|
609
606
|
}
|
|
610
607
|
}
|
|
@@ -655,46 +652,44 @@ class LibVlcPlayerView(
|
|
|
655
652
|
}
|
|
656
653
|
|
|
657
654
|
fun snapshot(path: String) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
val view = getTextureView(playerLayout) ?: throw Exception()
|
|
661
|
-
|
|
662
|
-
if (!hasVideoSize) throw Exception()
|
|
663
|
-
|
|
664
|
-
val surface = Surface(view.surfaceTexture)
|
|
665
|
-
val video = getVideoSize()
|
|
666
|
-
val bitmap = Bitmap.createBitmap(video.width, video.height, Bitmap.Config.ARGB_8888)
|
|
655
|
+
try {
|
|
656
|
+
val view = getTextureView(playerLayout) ?: throw Exception()
|
|
667
657
|
|
|
668
|
-
|
|
669
|
-
surface,
|
|
670
|
-
bitmap,
|
|
671
|
-
{ copyResult ->
|
|
672
|
-
if (copyResult != PixelCopy.SUCCESS) {
|
|
673
|
-
onEncounteredError(mapOf("error" to "Snapshot could not be taken"))
|
|
674
|
-
return@request
|
|
675
|
-
}
|
|
658
|
+
if (!hasVideoSize) throw Exception()
|
|
676
659
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
660
|
+
val surface = Surface(view.surfaceTexture)
|
|
661
|
+
val video = getVideoSize()
|
|
662
|
+
val bitmap = Bitmap.createBitmap(video.width, video.height, Bitmap.Config.ARGB_8888)
|
|
663
|
+
|
|
664
|
+
PixelCopy.request(
|
|
665
|
+
surface,
|
|
666
|
+
bitmap,
|
|
667
|
+
{ copyResult ->
|
|
668
|
+
if (copyResult != PixelCopy.SUCCESS) {
|
|
669
|
+
onEncounteredError(mapOf("error" to "Snapshot could not be taken"))
|
|
670
|
+
return@request
|
|
671
|
+
}
|
|
680
672
|
|
|
681
|
-
|
|
682
|
-
|
|
673
|
+
try {
|
|
674
|
+
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd-HH'h'mm'm'ss's'")
|
|
675
|
+
val timestamp = simpleDateFormat.format(Calendar.getInstance().time)
|
|
683
676
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
677
|
+
val snapshotPath = path + "/vlc-snapshot-$timestamp.jpg"
|
|
678
|
+
val file = File(snapshotPath)
|
|
687
679
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
onEncounteredError(mapOf("error" to "Snapshot could not be taken"))
|
|
680
|
+
FileOutputStream(file).use { stream ->
|
|
681
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
|
|
691
682
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
683
|
+
|
|
684
|
+
onSnapshotTaken(mapOf("path" to snapshotPath))
|
|
685
|
+
} catch (_: Exception) {
|
|
686
|
+
onEncounteredError(mapOf("error" to "Snapshot could not be taken"))
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
Handler(Looper.getMainLooper()),
|
|
690
|
+
)
|
|
691
|
+
} catch (_: Exception) {
|
|
692
|
+
onEncounteredError(mapOf("error" to "Snapshot could not be taken"))
|
|
698
693
|
}
|
|
699
694
|
}
|
|
700
695
|
|
|
@@ -157,7 +157,7 @@ class LibVlcPlayerView: ExpoView {
|
|
|
157
157
|
selectTrack(textTrack, .text)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
func addPlayerSlaves() {
|
|
160
|
+
func addPlayerSlaves(_ slaves: [Slave]) {
|
|
161
161
|
for slave in slaves {
|
|
162
162
|
let source = slave.source
|
|
163
163
|
let type = slave.type
|
|
@@ -220,7 +220,7 @@ class LibVlcPlayerView: ExpoView {
|
|
|
220
220
|
guard let self else { return }
|
|
221
221
|
|
|
222
222
|
if let player = mediaPlayer {
|
|
223
|
-
addPlayerSlaves()
|
|
223
|
+
addPlayerSlaves(slaves)
|
|
224
224
|
|
|
225
225
|
if scale != MediaPlayerConstants.defaultPlayerScale {
|
|
226
226
|
player.scaleFactor = scale
|
|
@@ -250,12 +250,10 @@ class LibVlcPlayerView: ExpoView {
|
|
|
250
250
|
func getMediaLength() -> Int32 {
|
|
251
251
|
var length: Int32 = 0
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
let duration = media.length.intValue
|
|
253
|
+
let duration = mediaPlayer?.media?.length.intValue ?? 0
|
|
255
254
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
255
|
+
if duration > 0 {
|
|
256
|
+
length = duration
|
|
259
257
|
}
|
|
260
258
|
|
|
261
259
|
return length
|
|
@@ -296,18 +294,16 @@ class LibVlcPlayerView: ExpoView {
|
|
|
296
294
|
func getMediaInfo() -> MediaInfo {
|
|
297
295
|
var mediaInfo = MediaInfo()
|
|
298
296
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
}
|
|
297
|
+
let video = getVideoSize()
|
|
298
|
+
let length = getMediaLength()
|
|
299
|
+
let seekable = mediaPlayer?.isSeekable ?? false
|
|
300
|
+
|
|
301
|
+
mediaInfo = MediaInfo(
|
|
302
|
+
width: Int(video.width),
|
|
303
|
+
height: Int(video.height),
|
|
304
|
+
length: Double(length),
|
|
305
|
+
seekable: seekable
|
|
306
|
+
)
|
|
311
307
|
|
|
312
308
|
return mediaInfo
|
|
313
309
|
}
|
|
@@ -364,7 +360,7 @@ class LibVlcPlayerView: ExpoView {
|
|
|
364
360
|
_slaves += newSlaves
|
|
365
361
|
|
|
366
362
|
if !newSlaves.isEmpty {
|
|
367
|
-
addPlayerSlaves()
|
|
363
|
+
addPlayerSlaves(newSlaves)
|
|
368
364
|
}
|
|
369
365
|
}
|
|
370
366
|
}
|
|
@@ -446,7 +442,10 @@ class LibVlcPlayerView: ExpoView {
|
|
|
446
442
|
func pauseIf(_ condition: Bool? = true) {
|
|
447
443
|
if let player = mediaPlayer {
|
|
448
444
|
let shouldPause = condition == true && player.isPlaying
|
|
449
|
-
|
|
445
|
+
|
|
446
|
+
if shouldPause {
|
|
447
|
+
player.pause()
|
|
448
|
+
}
|
|
450
449
|
}
|
|
451
450
|
}
|
|
452
451
|
|