expo-libvlc-player 3.4.13 → 3.4.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.
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'expo.modules.libvlcplayer'
4
- version = '3.4.13'
4
+ version = '3.4.15'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(':expo-modules-core').projectDir.absolutePath, 'ExpoModulesCorePlugin.gradle')
7
7
  apply from: expoModulesCorePlugin
@@ -25,7 +25,7 @@ android {
25
25
  targetSdkVersion safeExtGet('targetSdkVersion', 35)
26
26
 
27
27
  versionCode 1
28
- versionName '3.4.13'
28
+ versionName '3.4.15'
29
29
 
30
30
  consumerProguardFiles('proguard-rules.pro')
31
31
  }
@@ -5,8 +5,10 @@ import android.os.PowerManager
5
5
  import expo.modules.kotlin.exception.Exceptions
6
6
  import expo.modules.kotlin.modules.Module
7
7
  import expo.modules.kotlin.modules.ModuleDefinition
8
+ import expo.modules.libvlcplayer.constants.MediaPlayerConstants
8
9
  import expo.modules.libvlcplayer.enums.AudioMixingMode
9
10
  import expo.modules.libvlcplayer.enums.VideoContentFit
11
+ import expo.modules.libvlcplayer.managers.MediaPlayerManager
10
12
  import expo.modules.libvlcplayer.records.Slave
11
13
  import expo.modules.libvlcplayer.records.Tracks
12
14
 
@@ -83,56 +85,56 @@ class LibVlcPlayerModule : Module() {
83
85
  view.source = source
84
86
  }
85
87
 
86
- Prop("options") { view: LibVlcPlayerView, options: ArrayList<String>? ->
87
- view.options = options ?: ArrayList<String>()
88
+ Prop("options", ArrayList<String>()) { view: LibVlcPlayerView, options: ArrayList<String> ->
89
+ view.options = options
88
90
  }
89
91
 
90
92
  Prop("tracks") { view: LibVlcPlayerView, tracks: Tracks? ->
91
93
  view.tracks = tracks
92
94
  }
93
95
 
94
- Prop("slaves") { view: LibVlcPlayerView, slaves: ArrayList<Slave>? ->
95
- view.slaves = slaves ?: ArrayList<Slave>()
96
+ Prop("slaves", ArrayList<Slave>()) { view: LibVlcPlayerView, slaves: ArrayList<Slave> ->
97
+ view.slaves = slaves
96
98
  }
97
99
 
98
- Prop("scale") { view: LibVlcPlayerView, scale: Float? ->
99
- view.scale = scale ?: DEFAULT_PLAYER_SCALE
100
+ Prop("scale", MediaPlayerConstants.DEFAULT_PLAYER_SCALE) { view: LibVlcPlayerView, scale: Float ->
101
+ view.scale = scale
100
102
  }
101
103
 
102
- Prop("contentFit") { view: LibVlcPlayerView, contentFit: VideoContentFit? ->
103
- view.contentFit = contentFit ?: VideoContentFit.CONTAIN
104
+ Prop("contentFit", VideoContentFit.CONTAIN) { view: LibVlcPlayerView, contentFit: VideoContentFit ->
105
+ view.contentFit = contentFit
104
106
  }
105
107
 
106
- Prop("rate") { view: LibVlcPlayerView, rate: Float? ->
107
- view.rate = rate ?: DEFAULT_PLAYER_RATE
108
+ Prop("rate", MediaPlayerConstants.DEFAULT_PLAYER_RATE) { view: LibVlcPlayerView, rate: Float ->
109
+ view.rate = rate
108
110
  }
109
111
 
110
- Prop("time") { view: LibVlcPlayerView, time: Int? ->
111
- view.time = time ?: DEFAULT_PLAYER_TIME
112
+ Prop("time", MediaPlayerConstants.DEFAULT_PLAYER_TIME) { view: LibVlcPlayerView, time: Int ->
113
+ view.time = time
112
114
  }
113
115
 
114
- Prop("volume") { view: LibVlcPlayerView, volume: Int? ->
115
- view.volume = volume ?: MAX_PLAYER_VOLUME
116
+ Prop("volume", MediaPlayerConstants.MAX_PLAYER_VOLUME) { view: LibVlcPlayerView, volume: Int ->
117
+ view.volume = volume
116
118
  }
117
119
 
118
- Prop("mute") { view: LibVlcPlayerView, mute: Boolean? ->
119
- view.mute = mute ?: false
120
+ Prop("mute", false) { view: LibVlcPlayerView, mute: Boolean ->
121
+ view.mute = mute
120
122
  }
121
123
 
122
- Prop("audioMixingMode") { view: LibVlcPlayerView, audioMixingMode: AudioMixingMode? ->
123
- view.audioMixingMode = audioMixingMode ?: AudioMixingMode.AUTO
124
+ Prop("audioMixingMode", AudioMixingMode.AUTO) { view: LibVlcPlayerView, audioMixingMode: AudioMixingMode ->
125
+ view.audioMixingMode = audioMixingMode
124
126
  }
125
127
 
126
- Prop("playInBackground") { view: LibVlcPlayerView, playInBackground: Boolean? ->
127
- view.playInBackground = playInBackground ?: false
128
+ Prop("playInBackground", false) { view: LibVlcPlayerView, playInBackground: Boolean ->
129
+ view.playInBackground = playInBackground
128
130
  }
129
131
 
130
- Prop("repeat") { view: LibVlcPlayerView, repeat: Boolean? ->
131
- view.repeat = repeat ?: false
132
+ Prop("repeat", false) { view: LibVlcPlayerView, repeat: Boolean ->
133
+ view.repeat = repeat
132
134
  }
133
135
 
134
- Prop("autoplay") { view: LibVlcPlayerView, autoplay: Boolean? ->
135
- view.autoplay = autoplay ?: true
136
+ Prop("autoplay", true) { view: LibVlcPlayerView, autoplay: Boolean ->
137
+ view.autoplay = autoplay
136
138
  }
137
139
 
138
140
  OnViewDidUpdateProps { view: LibVlcPlayerView ->
@@ -12,8 +12,10 @@ import android.view.TextureView
12
12
  import expo.modules.kotlin.AppContext
13
13
  import expo.modules.kotlin.viewevent.EventDispatcher
14
14
  import expo.modules.kotlin.views.ExpoView
15
+ import expo.modules.libvlcplayer.constants.MediaPlayerConstants
15
16
  import expo.modules.libvlcplayer.enums.AudioMixingMode
16
17
  import expo.modules.libvlcplayer.enums.VideoContentFit
18
+ import expo.modules.libvlcplayer.managers.MediaPlayerManager
17
19
  import expo.modules.libvlcplayer.records.Dialog
18
20
  import expo.modules.libvlcplayer.records.MediaInfo
19
21
  import expo.modules.libvlcplayer.records.MediaTracks
@@ -24,6 +26,8 @@ import expo.modules.libvlcplayer.records.Tracks
24
26
  import org.videolan.libvlc.LibVLC
25
27
  import org.videolan.libvlc.Media
26
28
  import org.videolan.libvlc.MediaPlayer
29
+ import org.videolan.libvlc.MediaPlayer.Event
30
+ import org.videolan.libvlc.MediaPlayer.EventListener
27
31
  import org.videolan.libvlc.interfaces.IMedia
28
32
  import org.videolan.libvlc.util.DisplayManager
29
33
  import org.videolan.libvlc.util.VLCVideoLayout
@@ -34,14 +38,6 @@ import java.text.SimpleDateFormat
34
38
  import java.util.Calendar
35
39
  import org.videolan.libvlc.Dialog as VLCDialog
36
40
 
37
- const val DEFAULT_PLAYER_RATE: Float = 1f
38
- const val DEFAULT_PLAYER_TIME: Int = 0
39
- const val DEFAULT_PLAYER_SCALE: Float = 0f
40
-
41
- const val MIN_PLAYER_VOLUME: Int = 0
42
- const val MAX_PLAYER_VOLUME: Int = 100
43
- const val PLAYER_VOLUME_STEP: Int = 10
44
-
45
41
  private val DISPLAY_MANAGER: DisplayManager? = null
46
42
  private val ENABLE_SUBTITLES: Boolean = true
47
43
  private val USE_TEXTURE_VIEW: Boolean = true
@@ -62,7 +58,7 @@ class LibVlcPlayerView(
62
58
 
63
59
  var mediaLength: Long? = null
64
60
 
65
- private var shouldCreate: Boolean = false
61
+ private var shouldCreate: Boolean = true
66
62
  var firstPlay: Boolean = false
67
63
  var firstTime: Boolean = false
68
64
 
@@ -120,9 +116,10 @@ class LibVlcPlayerView(
120
116
 
121
117
  val source = source ?: return
122
118
 
123
- options.toggleStartPausedOption(autoplay)
119
+ var initOptions = options
120
+ initOptions.toggleStartPausedOption(autoplay)
124
121
 
125
- libVLC = LibVLC(context, options)
122
+ libVLC = LibVLC(context, initOptions)
126
123
  setDialogCallbacks()
127
124
  mediaPlayer = MediaPlayer(libVLC)
128
125
  setMediaPlayerListener()
@@ -167,12 +164,12 @@ class LibVlcPlayerView(
167
164
  }
168
165
 
169
166
  fun destroyPlayer() {
170
- vlcDialog = null
171
- media = null
172
- mediaPlayer?.release()
173
- mediaPlayer = null
174
167
  libVLC?.release()
175
168
  libVLC = null
169
+ mediaPlayer?.release()
170
+ mediaPlayer = null
171
+ media = null
172
+ vlcDialog = null
176
173
  removeAllViews()
177
174
  }
178
175
 
@@ -347,22 +344,22 @@ class LibVlcPlayerView(
347
344
  mediaPlayer?.let { player ->
348
345
  setPlayerTracks()
349
346
 
350
- if (scale != DEFAULT_PLAYER_SCALE) {
347
+ if (scale != MediaPlayerConstants.DEFAULT_PLAYER_SCALE) {
351
348
  player.setScale(scale)
352
349
  }
353
350
 
354
- if (rate != DEFAULT_PLAYER_RATE) {
351
+ if (rate != MediaPlayerConstants.DEFAULT_PLAYER_RATE) {
355
352
  player.setRate(rate)
356
353
  }
357
354
 
358
- if (time != DEFAULT_PLAYER_TIME) {
355
+ if (time != MediaPlayerConstants.DEFAULT_PLAYER_TIME) {
359
356
  player.setTime(time.toLong())
360
357
  }
361
358
 
362
- if (volume != MAX_PLAYER_VOLUME || mute) {
359
+ if (volume != MediaPlayerConstants.MAX_PLAYER_VOLUME || mute) {
363
360
  val newVolume =
364
361
  if (mute) {
365
- MIN_PLAYER_VOLUME
362
+ MediaPlayerConstants.MIN_PLAYER_VOLUME
366
363
  } else {
367
364
  volume
368
365
  }
@@ -370,7 +367,7 @@ class LibVlcPlayerView(
370
367
  player.setVolume(newVolume)
371
368
  }
372
369
 
373
- time = DEFAULT_PLAYER_TIME
370
+ time = MediaPlayerConstants.DEFAULT_PLAYER_TIME
374
371
  }
375
372
  }
376
373
 
@@ -378,14 +375,14 @@ class LibVlcPlayerView(
378
375
  set(value) {
379
376
  val old = field
380
377
  field = value
381
- shouldCreate = value != old
378
+ shouldCreate = true
382
379
  }
383
380
 
384
381
  var options: ArrayList<String> = ArrayList()
385
382
  set(value) {
386
383
  val old = field
387
384
  field = value
388
- shouldCreate = value != old
385
+ shouldCreate = true
389
386
  }
390
387
 
391
388
  var tracks: Tracks? = null
@@ -405,7 +402,7 @@ class LibVlcPlayerView(
405
402
  }
406
403
  }
407
404
 
408
- var scale: Float = DEFAULT_PLAYER_SCALE
405
+ var scale: Float = MediaPlayerConstants.DEFAULT_PLAYER_SCALE
409
406
  set(value) {
410
407
  field = value
411
408
  mediaPlayer?.setScale(value)
@@ -417,23 +414,19 @@ class LibVlcPlayerView(
417
414
  setContentFit()
418
415
  }
419
416
 
420
- var rate: Float = DEFAULT_PLAYER_RATE
417
+ var rate: Float = MediaPlayerConstants.DEFAULT_PLAYER_RATE
421
418
  set(value) {
422
419
  field = value
423
420
  mediaPlayer?.setRate(value)
424
421
  }
425
422
 
426
- var time: Int = DEFAULT_PLAYER_TIME
423
+ var time: Int = MediaPlayerConstants.DEFAULT_PLAYER_TIME
427
424
 
428
- var volume: Int = MAX_PLAYER_VOLUME
425
+ var volume: Int = MediaPlayerConstants.MAX_PLAYER_VOLUME
429
426
  set(value) {
430
427
  field = value
431
428
 
432
- if (options.hasAudioOption()) {
433
- onEncounteredError(mapOf("error" to "Audio disabled via options"))
434
- }
435
-
436
- val newVolume = value.coerceIn(MIN_PLAYER_VOLUME, MAX_PLAYER_VOLUME)
429
+ val newVolume = value.coerceIn(MediaPlayerConstants.MIN_PLAYER_VOLUME, MediaPlayerConstants.MAX_PLAYER_VOLUME)
437
430
  MediaPlayerManager.audioFocusManager.oldVolume = newVolume
438
431
 
439
432
  if (!mute) {
@@ -446,13 +439,9 @@ class LibVlcPlayerView(
446
439
  set(value) {
447
440
  field = value
448
441
 
449
- if (options.hasAudioOption()) {
450
- onEncounteredError(mapOf("error" to "Audio disabled via options"))
451
- }
452
-
453
442
  val newVolume =
454
443
  if (value) {
455
- MIN_PLAYER_VOLUME
444
+ MediaPlayerConstants.MIN_PLAYER_VOLUME
456
445
  } else {
457
446
  MediaPlayerManager.audioFocusManager.oldVolume
458
447
  }
@@ -476,10 +465,6 @@ class LibVlcPlayerView(
476
465
  var repeat: Boolean = false
477
466
  set(value) {
478
467
  field = value
479
-
480
- if (options.hasRepeatOption()) {
481
- onEncounteredError(mapOf("error" to "Repeat enabled via options"))
482
- }
483
468
  }
484
469
 
485
470
  var autoplay: Boolean = true
@@ -600,56 +585,188 @@ class LibVlcPlayerView(
600
585
  vlcDialog = null
601
586
  }
602
587
  }
588
+ }
603
589
 
604
- private fun ArrayList<String>.hasAudioOption(): Boolean {
605
- val options =
606
- setOf(
607
- "--no-audio",
608
- "-no-audio",
609
- ":no-audio",
610
- )
590
+ fun LibVlcPlayerView.setMediaPlayerListener() {
591
+ mediaPlayer?.let { player ->
592
+ player.setEventListener(
593
+ EventListener { event ->
594
+ when (event.type) {
595
+ Event.Buffering -> {
596
+ onBuffering(Unit)
597
+ }
611
598
 
612
- return this.any { option -> option in options }
613
- }
599
+ Event.Playing -> {
600
+ onPlaying(Unit)
614
601
 
615
- fun ArrayList<String>.hasRepeatOption(): Boolean {
616
- val options =
617
- setOf(
618
- "--input-repeat=",
619
- "-input-repeat=",
620
- ":input-repeat=",
621
- )
622
-
623
- return this.any { option ->
624
- options.any { value ->
625
- option.startsWith(value)
626
- }
627
- }
602
+ if (firstPlay) {
603
+ attachPlayer()
604
+
605
+ setupPlayer()
606
+
607
+ onFirstPlay(getMediaInfo())
608
+
609
+ firstPlay = false
610
+ }
611
+
612
+ MediaPlayerManager.keepAwakeManager.activateKeepAwake()
613
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
614
+ }
615
+
616
+ Event.Paused -> {
617
+ onPaused(Unit)
618
+
619
+ MediaPlayerManager.keepAwakeManager.deactivateKeepAwake()
620
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
621
+ }
622
+
623
+ Event.Stopped -> {
624
+ onStopped(Unit)
625
+
626
+ detachPlayer()
627
+
628
+ MediaPlayerManager.keepAwakeManager.deactivateKeepAwake()
629
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
630
+
631
+ firstPlay = true
632
+ firstTime = true
633
+ }
634
+
635
+ Event.EndReached -> {
636
+ onEndReached(Unit)
637
+
638
+ player.stop()
639
+
640
+ if (repeat) {
641
+ player.play()
642
+ }
643
+ }
644
+
645
+ Event.EncounteredError -> {
646
+ onEncounteredError(mapOf("error" to "Media player encountered an error"))
647
+
648
+ MediaPlayerManager.keepAwakeManager.deactivateKeepAwake()
649
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
650
+
651
+ firstPlay = true
652
+ firstTime = true
653
+ }
654
+
655
+ Event.TimeChanged -> {
656
+ onTimeChanged(mapOf("time" to player.getTime().toInt()))
657
+
658
+ if (firstTime) {
659
+ if (mediaLength == null) {
660
+ onFirstPlay(getMediaInfo())
661
+ }
662
+
663
+ setContentFit()
664
+
665
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
666
+
667
+ firstTime = false
668
+ }
669
+ }
670
+
671
+ Event.PositionChanged -> {
672
+ onPositionChanged(mapOf("position" to player.getPosition()))
673
+ }
674
+
675
+ Event.ESAdded -> {
676
+ onESAdded(getMediaTracks())
677
+ }
678
+
679
+ Event.RecordChanged -> {
680
+ val recording =
681
+ Recording(
682
+ path = event.getRecordPath(),
683
+ isRecording = event.getRecording(),
684
+ )
685
+
686
+ onRecordChanged(recording)
687
+ }
688
+ }
689
+ },
690
+ )
628
691
  }
692
+ }
693
+
694
+ fun LibVlcPlayerView.setDialogCallbacks() {
695
+ libVLC?.let {
696
+ VLCDialog.setCallbacks(
697
+ it,
698
+ object : VLCDialog.Callbacks {
699
+ override fun onDisplay(dialog: VLCDialog.ErrorMessage) {
700
+ vlcDialog = dialog
701
+
702
+ val dialog =
703
+ Dialog(
704
+ title = dialog.getTitle(),
705
+ text = dialog.getText(),
706
+ )
707
+
708
+ onDialogDisplay(dialog)
709
+ }
710
+
711
+ override fun onDisplay(dialog: VLCDialog.LoginDialog) {
712
+ vlcDialog = dialog
713
+
714
+ val dialog =
715
+ Dialog(
716
+ title = dialog.getTitle(),
717
+ text = dialog.getText(),
718
+ )
719
+
720
+ onDialogDisplay(dialog)
721
+ }
722
+
723
+ override fun onDisplay(dialog: VLCDialog.QuestionDialog) {
724
+ vlcDialog = dialog
629
725
 
630
- private fun ArrayList<String>.hasStartPausedOption(): Boolean {
631
- val options =
632
- setOf(
633
- "--start-paused",
634
- "-start-paused",
635
- ":start-paused",
636
- )
726
+ val dialog =
727
+ Dialog(
728
+ title = dialog.getTitle(),
729
+ text = dialog.getText(),
730
+ cancelText = dialog.getCancelText(),
731
+ action1Text = dialog.getAction1Text(),
732
+ action2Text = dialog.getAction2Text(),
733
+ )
637
734
 
638
- return this.any { option -> option in options }
735
+ onDialogDisplay(dialog)
736
+ }
737
+
738
+ override fun onDisplay(dialog: VLCDialog.ProgressDialog) {}
739
+
740
+ override fun onCanceled(dialog: VLCDialog) {}
741
+
742
+ override fun onProgressUpdate(dialog: VLCDialog.ProgressDialog) {}
743
+ },
744
+ )
639
745
  }
746
+ }
640
747
 
641
- private fun ArrayList<String>.toggleStartPausedOption(autoplay: Boolean) {
642
- val options =
643
- setOf(
644
- "--start-paused",
645
- "-start-paused",
646
- ":start-paused",
647
- )
748
+ private fun ArrayList<String>.hasStartPausedOption(): Boolean {
749
+ val options =
750
+ setOf(
751
+ "--start-paused",
752
+ "-start-paused",
753
+ ":start-paused",
754
+ )
648
755
 
649
- this.removeAll(options)
756
+ return this.any { option -> option in options }
757
+ }
650
758
 
651
- if (!autoplay) {
652
- this.add("--start-paused")
653
- }
759
+ private fun ArrayList<String>.toggleStartPausedOption(autoplay: Boolean) {
760
+ val options =
761
+ setOf(
762
+ "--start-paused",
763
+ "-start-paused",
764
+ ":start-paused",
765
+ )
766
+
767
+ this.removeAll(options)
768
+
769
+ if (!autoplay) {
770
+ this.add("--start-paused")
654
771
  }
655
772
  }
@@ -0,0 +1,9 @@
1
+ package expo.modules.libvlcplayer.constants
2
+
3
+ object MediaPlayerConstants {
4
+ const val DEFAULT_PLAYER_SCALE: Float = 0f
5
+ const val DEFAULT_PLAYER_RATE: Float = 1f
6
+ const val DEFAULT_PLAYER_TIME: Int = 0
7
+ const val MIN_PLAYER_VOLUME: Int = 0
8
+ const val MAX_PLAYER_VOLUME: Int = 100
9
+ }
@@ -1,4 +1,4 @@
1
- package expo.modules.libvlcplayer
1
+ package expo.modules.libvlcplayer.managers
2
2
 
3
3
  import android.content.Context
4
4
  import android.media.AudioAttributes
@@ -7,6 +7,7 @@ import android.media.AudioManager
7
7
  import android.os.Build
8
8
  import expo.modules.kotlin.AppContext
9
9
  import expo.modules.kotlin.exception.Exceptions
10
+ import expo.modules.libvlcplayer.constants.MediaPlayerConstants
10
11
  import expo.modules.libvlcplayer.enums.AudioMixingMode
11
12
  import kotlinx.coroutines.launch
12
13
  import org.videolan.libvlc.MediaPlayer
@@ -23,23 +24,21 @@ class AudioFocusManager(
23
24
  }
24
25
  }
25
26
 
26
- private val playerViews = MediaPlayerManager.playerViews
27
-
28
27
  private var currentFocusRequest: AudioFocusRequest? = null
29
28
 
30
29
  private val anyPlayerRequiresFocus: Boolean
31
30
  get() =
32
- playerViews.toList().any { view ->
31
+ MediaPlayerManager.playerViews.toList().any { view ->
33
32
  playerRequiresFocus(view.get()?.mediaPlayer)
34
33
  }
35
34
 
36
35
  var currentMixingMode: AudioMixingMode = AudioMixingMode.AUTO
37
36
 
38
- var oldVolume: Int = MAX_PLAYER_VOLUME
37
+ var oldVolume: Int = MediaPlayerConstants.MAX_PLAYER_VOLUME
39
38
 
40
39
  private fun playerRequiresFocus(player: MediaPlayer?): Boolean {
41
40
  if (player != null) {
42
- return player.isPlaying() && player.getVolume() > MIN_PLAYER_VOLUME
41
+ return player.isPlaying() && player.getVolume() > MediaPlayerConstants.MIN_PLAYER_VOLUME
43
42
  } else {
44
43
  return false
45
44
  }
@@ -47,7 +46,7 @@ class AudioFocusManager(
47
46
 
48
47
  private fun findAudioMixingMode(): AudioMixingMode {
49
48
  val mixingModes =
50
- playerViews.toList().mapNotNull { playerView ->
49
+ MediaPlayerManager.playerViews.toList().mapNotNull { playerView ->
51
50
  playerView
52
51
  .get()
53
52
  ?.takeIf { view ->
@@ -103,6 +102,7 @@ class AudioFocusManager(
103
102
  currentFocusRequest = newFocusRequest
104
103
  audioManager.requestAudioFocus(newFocusRequest)
105
104
  } else {
105
+ @Suppress("DEPRECATION")
106
106
  audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, audioFocusType)
107
107
  }
108
108
 
@@ -114,6 +114,7 @@ class AudioFocusManager(
114
114
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
115
115
  audioManager.abandonAudioFocusRequest(it)
116
116
  } else {
117
+ @Suppress("DEPRECATION")
117
118
  audioManager.abandonAudioFocus(this)
118
119
  }
119
120
  }
@@ -131,7 +132,7 @@ class AudioFocusManager(
131
132
 
132
133
  private fun pausePlayerIfUnmuted(player: MediaPlayer?) {
133
134
  player?.let { mediaPlayer ->
134
- if (mediaPlayer.getVolume() > MIN_PLAYER_VOLUME) {
135
+ if (mediaPlayer.getVolume() > MediaPlayerConstants.MIN_PLAYER_VOLUME) {
135
136
  mediaPlayer.pause()
136
137
  }
137
138
  }
@@ -147,7 +148,7 @@ class AudioFocusManager(
147
148
 
148
149
  private fun unduckPlayer(player: MediaPlayer?) {
149
150
  player?.let { mediaPlayer ->
150
- if (mediaPlayer.getVolume() > MIN_PLAYER_VOLUME) {
151
+ if (mediaPlayer.getVolume() > MediaPlayerConstants.MIN_PLAYER_VOLUME) {
151
152
  mediaPlayer.setVolume(oldVolume)
152
153
  }
153
154
  }
@@ -157,7 +158,7 @@ class AudioFocusManager(
157
158
  when (focusChange) {
158
159
  AudioManager.AUDIOFOCUS_LOSS -> {
159
160
  appContext.mainQueue.launch {
160
- playerViews.forEach { view ->
161
+ MediaPlayerManager.playerViews.forEach { view ->
161
162
  pausePlayerIfUnmuted(view.get()?.mediaPlayer)
162
163
  }
163
164
 
@@ -173,7 +174,7 @@ class AudioFocusManager(
173
174
  }
174
175
 
175
176
  appContext.mainQueue.launch {
176
- playerViews.forEach { view ->
177
+ MediaPlayerManager.playerViews.forEach { view ->
177
178
  pausePlayerIfUnmuted(view.get()?.mediaPlayer)
178
179
  }
179
180
 
@@ -185,7 +186,7 @@ class AudioFocusManager(
185
186
  val audioMixingMode = findAudioMixingMode()
186
187
 
187
188
  appContext.mainQueue.launch {
188
- playerViews.forEach { view ->
189
+ MediaPlayerManager.playerViews.forEach { view ->
189
190
  view.get()?.mediaPlayer?.let { player ->
190
191
  if (audioMixingMode == AudioMixingMode.DO_NOT_MIX) {
191
192
  pausePlayerIfUnmuted(player)
@@ -199,7 +200,7 @@ class AudioFocusManager(
199
200
 
200
201
  AudioManager.AUDIOFOCUS_GAIN -> {
201
202
  appContext.mainQueue.launch {
202
- playerViews.forEach { view ->
203
+ MediaPlayerManager.playerViews.forEach { view ->
203
204
  unduckPlayer(view.get()?.mediaPlayer)
204
205
  }
205
206
  }
@@ -1,4 +1,4 @@
1
- package expo.modules.libvlcplayer
1
+ package expo.modules.libvlcplayer.managers
2
2
 
3
3
  import android.app.Activity
4
4
  import android.view.WindowManager
@@ -1,6 +1,7 @@
1
- package expo.modules.libvlcplayer
1
+ package expo.modules.libvlcplayer.managers
2
2
 
3
3
  import expo.modules.kotlin.AppContext
4
+ import expo.modules.libvlcplayer.LibVlcPlayerView
4
5
  import java.lang.ref.WeakReference
5
6
 
6
7
  object MediaPlayerManager {
@@ -0,0 +1,7 @@
1
+ enum MediaPlayerConstants {
2
+ static let defaultPlayerScale: Float = 0.0
3
+ static let defaultPlayerRate: Float = 1.0
4
+ static let defaultPlayerTime: Int = 0
5
+ static let minPlayerVolume: Int = 0
6
+ static let maxPlayerVolume: Int = 100
7
+ }