expo-libvlc-player 7.0.25 → 7.0.26

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.
@@ -502,6 +502,7 @@ class LibVlcPlayerView(
502
502
 
503
503
  var volume: Int = MediaPlayerConstants.MAX_PLAYER_VOLUME
504
504
  set(value) {
505
+ val oldValue = field
505
506
  field = value
506
507
 
507
508
  if (mute) return
@@ -511,9 +512,15 @@ class LibVlcPlayerView(
511
512
  MediaPlayerConstants.MIN_PLAYER_VOLUME,
512
513
  MediaPlayerConstants.MAX_PLAYER_VOLUME,
513
514
  )
515
+
514
516
  mediaPlayer?.setVolume(newVolume)
515
517
 
516
- MediaPlayerManager.audioFocusManager.updateAudioFocus()
518
+ val hadVolume = oldValue > MediaPlayerConstants.MIN_PLAYER_VOLUME
519
+ val hasVolume = newVolume > MediaPlayerConstants.MIN_PLAYER_VOLUME
520
+
521
+ if (hadVolume != hasVolume) {
522
+ MediaPlayerManager.audioFocusManager.updateAudioFocus()
523
+ }
517
524
  }
518
525
 
519
526
  var mute: Boolean = false
@@ -31,7 +31,7 @@ class AudioFocusManager(
31
31
 
32
32
  private var currentFocusRequest: AudioFocusRequest? = null
33
33
 
34
- private val anyPlayerRequiresFocus: Boolean
34
+ private val anyPlayingView: Boolean
35
35
  get() =
36
36
  expoViews.any { view ->
37
37
  playerRequiresFocus(view.mediaPlayer)
@@ -89,7 +89,7 @@ class AudioFocusManager(
89
89
 
90
90
  fun updateAudioFocus() {
91
91
  appContext.mainQueue.launch {
92
- if (anyPlayerRequiresFocus || findAudioMixingMode() != currentMixingMode) {
92
+ if (anyPlayingView || findAudioMixingMode() != currentMixingMode) {
93
93
  requestAudioFocus()
94
94
  } else {
95
95
  abandonAudioFocus()
@@ -97,12 +97,10 @@ class AudioFocusManager(
97
97
  }
98
98
  }
99
99
 
100
- private fun playerRequiresFocus(player: MediaPlayer?): Boolean =
101
- if (player != null) {
102
- player.isPlaying() && player.getVolume() > MediaPlayerConstants.MIN_PLAYER_VOLUME
103
- } else {
104
- false
105
- }
100
+ private fun playerRequiresFocus(mediaPlayer: MediaPlayer?): Boolean {
101
+ val player = mediaPlayer ?: return false
102
+ return player.isPlaying() && player.getVolume() > MediaPlayerConstants.MIN_PLAYER_VOLUME
103
+ }
106
104
 
107
105
  private fun findAudioMixingMode(): AudioMixingMode {
108
106
  val mixingModes =
@@ -122,7 +120,7 @@ class AudioFocusManager(
122
120
  private fun requestAudioFocus() {
123
121
  val audioMixingMode = findAudioMixingMode()
124
122
 
125
- if (audioMixingMode == AudioMixingMode.MIX_WITH_OTHERS || !anyPlayerRequiresFocus) {
123
+ if (audioMixingMode == AudioMixingMode.MIX_WITH_OTHERS || !anyPlayingView) {
126
124
  abandonAudioFocus()
127
125
  currentMixingMode = audioMixingMode
128
126
  return
@@ -395,9 +395,15 @@ class LibVlcPlayerView: ExpoView {
395
395
  MediaPlayerConstants.minPlayerVolume,
396
396
  min(MediaPlayerConstants.maxPlayerVolume, volume)
397
397
  )
398
+
398
399
  mediaPlayer?.audio?.volume = Int32(newVolume)
399
400
 
400
- MediaPlayerManager.shared.audioSessionManager.setAppropriateAudioSession()
401
+ let hadVolume = oldValue > MediaPlayerConstants.minPlayerVolume
402
+ let hasVolume = newVolume > MediaPlayerConstants.minPlayerVolume
403
+
404
+ if hadVolume != hasVolume {
405
+ MediaPlayerManager.shared.audioSessionManager.setAppropriateAudioSession()
406
+ }
401
407
  }
402
408
  }
403
409
 
@@ -1,6 +1,7 @@
1
1
  import AVFoundation
2
2
  import ExpoModulesCore
3
3
  import Foundation
4
+ import VLCKit
4
5
 
5
6
  class AudioSessionManager {
6
7
  static let shared = AudioSessionManager()
@@ -21,11 +22,7 @@ class AudioSessionManager {
21
22
  var audioSessionCategoryOptions: AVAudioSession.CategoryOptions = audioSession.categoryOptions
22
23
 
23
24
  let anyPlayingView = expoViews.allObjects.contains { view in
24
- if let player = view.mediaPlayer, let audio = player.audio {
25
- player.isPlaying && audio.volume > MediaPlayerConstants.minPlayerVolume
26
- } else {
27
- false
28
- }
25
+ playerRequiresCategory(view.mediaPlayer)
29
26
  }
30
27
 
31
28
  let shouldMixOverride = audioMixingMode == .mixWithOthers
@@ -54,15 +51,18 @@ class AudioSessionManager {
54
51
  }
55
52
  }
56
53
 
57
- if anyPlayingView || doNotMixOverride {
58
- do {
59
- try audioSession.setActive(true)
60
- } catch {
61
- log.warn("Failed to activate the audio session")
62
- }
54
+ do {
55
+ try audioSession.setActive(anyPlayingView || doNotMixOverride)
56
+ } catch {
57
+ log.warn("Failed to set the audio session")
63
58
  }
64
59
  }
65
60
 
61
+ private func playerRequiresCategory(_ mediaPlayer: VLCMediaPlayer?) -> Bool {
62
+ guard let player = mediaPlayer, let audio = player.audio else { return false }
63
+ return player.isPlaying && audio.volume > MediaPlayerConstants.minPlayerVolume
64
+ }
65
+
66
66
  private func findAudioMixingMode() -> AudioMixingMode? {
67
67
  let playingViews = expoViews.allObjects.filter { view in
68
68
  view.mediaPlayer?.isPlaying == true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-libvlc-player",
3
- "version": "7.0.25",
3
+ "version": "7.0.26",
4
4
  "description": "LibVLC Player for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",