expo-libvlc-player 2.0.9 → 2.0.10

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 = "2.0.9"
4
+ version = "2.0.10"
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 "2.0.9"
30
+ versionName "2.0.10"
31
31
  consumerProguardFiles("proguard-rules.pro")
32
32
  }
33
33
  lintOptions {
@@ -0,0 +1,77 @@
1
+ import AVFoundation
2
+ import ExpoModulesCore
3
+ import Foundation
4
+
5
+ extension MediaPlayerManager {
6
+ private static let managerQueue = DispatchQueue(label: "audioManagerQueue")
7
+
8
+ func setAppropriateAudioSession() {
9
+ Self.managerQueue.async { [weak self] in
10
+ self?.setAudioSession()
11
+ }
12
+ }
13
+
14
+ private func setAudioSession() {
15
+ let audioSession = AVAudioSession.sharedInstance()
16
+ let audioMixingMode = findAudioMixingMode()
17
+ var audioSessionCategoryOptions: AVAudioSession.CategoryOptions = audioSession.categoryOptions
18
+
19
+ let isOutputtingAudio = playerViews.allObjects.contains { view in
20
+ guard let player = view.mediaPlayer else { return false }
21
+
22
+ return player.isPlaying && player.audio?.isMuted == false
23
+ }
24
+
25
+ let shouldMixOverride = audioMixingMode == .mixWithOthers
26
+ let doNotMixOverride = audioMixingMode == .doNotMix
27
+ let shouldDuckOthers = audioMixingMode == .duckOthers && isOutputtingAudio
28
+
29
+ let shouldMixWithOthers = shouldMixOverride || !isOutputtingAudio
30
+
31
+ if shouldMixWithOthers && !shouldDuckOthers && !doNotMixOverride {
32
+ audioSessionCategoryOptions.insert(.mixWithOthers)
33
+ } else {
34
+ audioSessionCategoryOptions.remove(.mixWithOthers)
35
+ }
36
+
37
+ if shouldDuckOthers && !doNotMixOverride {
38
+ audioSessionCategoryOptions.insert(.duckOthers)
39
+ } else {
40
+ audioSessionCategoryOptions.remove(.duckOthers)
41
+ }
42
+
43
+ if audioSession.categoryOptions != audioSessionCategoryOptions || audioSession.category != .playback || audioSession.mode != .moviePlayback {
44
+ do {
45
+ try audioSession.setCategory(.playback, mode: .moviePlayback, options: audioSessionCategoryOptions)
46
+ } catch {
47
+ log.warn("Failed to set audio session category")
48
+ }
49
+ }
50
+
51
+ if isOutputtingAudio || doNotMixOverride {
52
+ do {
53
+ try audioSession.setActive(true)
54
+ } catch {
55
+ log.warn("Failed to activate the audio session")
56
+ }
57
+ }
58
+ }
59
+
60
+ private func findAudioMixingMode() -> AudioMixingMode? {
61
+ let playingViews = playerViews.allObjects.filter { view in
62
+ view.mediaPlayer?.isPlaying == true
63
+ }
64
+
65
+ var audioMixingMode: AudioMixingMode = .auto
66
+
67
+ if playingViews.isEmpty {
68
+ return nil
69
+ }
70
+
71
+ for playerView in playingViews where (audioMixingMode.priority()) < playerView.audioMixingMode.priority() {
72
+ audioMixingMode = playerView.audioMixingMode
73
+ }
74
+
75
+ return audioMixingMode
76
+ }
77
+ }
@@ -1,13 +1,9 @@
1
- import AVFoundation
2
- import ExpoModulesCore
3
1
  import Foundation
4
- import MobileVLCKit
5
2
 
6
3
  class MediaPlayerManager {
7
4
  static let shared = MediaPlayerManager()
8
5
 
9
- private static let managerQueue = DispatchQueue(label: "com.expo.libvlcplayer.manager.managerQueue")
10
- private let playerViews = NSHashTable<LibVlcPlayerView>.weakObjects()
6
+ let playerViews = NSHashTable<LibVlcPlayerView>.weakObjects()
11
7
 
12
8
  func onModuleDestroyed() {
13
9
  for view in playerViews.allObjects {
@@ -36,76 +32,4 @@ class MediaPlayerManager {
36
32
  }
37
33
  }
38
34
  }
39
-
40
- func setAppropriateAudioSession() {
41
- Self.managerQueue.async { [weak self] in
42
- self?.setAudioSession()
43
- }
44
- }
45
-
46
- private func setAudioSession() {
47
- let audioSession = AVAudioSession.sharedInstance()
48
- let audioMixingMode = findAudioMixingMode()
49
- var audioSessionCategoryOptions: AVAudioSession.CategoryOptions = audioSession.categoryOptions
50
-
51
- let isOutputtingAudio = playerViews.allObjects.contains { view in
52
- if let player = view.mediaPlayer, let audio = player.audio {
53
- return player.isPlaying && audio.volume > minPlayerVolume
54
- } else {
55
- return false
56
- }
57
- }
58
-
59
- let shouldMixOverride = audioMixingMode == .mixWithOthers
60
- let doNotMixOverride = audioMixingMode == .doNotMix
61
- let shouldDuckOthers = audioMixingMode == .duckOthers && isOutputtingAudio
62
-
63
- let shouldMixWithOthers = shouldMixOverride || !isOutputtingAudio
64
-
65
- if shouldMixWithOthers && !shouldDuckOthers && !doNotMixOverride {
66
- audioSessionCategoryOptions.insert(.mixWithOthers)
67
- } else {
68
- audioSessionCategoryOptions.remove(.mixWithOthers)
69
- }
70
-
71
- if shouldDuckOthers && !doNotMixOverride {
72
- audioSessionCategoryOptions.insert(.duckOthers)
73
- } else {
74
- audioSessionCategoryOptions.remove(.duckOthers)
75
- }
76
-
77
- if audioSession.categoryOptions != audioSessionCategoryOptions || audioSession.category != .playback || audioSession.mode != .moviePlayback {
78
- do {
79
- try audioSession.setCategory(.playback, mode: .moviePlayback, options: audioSessionCategoryOptions)
80
- } catch {
81
- log.warn("Failed to set audio session category")
82
- }
83
- }
84
-
85
- if isOutputtingAudio || doNotMixOverride {
86
- do {
87
- try audioSession.setActive(true)
88
- } catch {
89
- log.warn("Failed to activate the audio session")
90
- }
91
- }
92
- }
93
-
94
- private func findAudioMixingMode() -> AudioMixingMode? {
95
- let playingViews = playerViews.allObjects.filter { view in
96
- view.mediaPlayer?.isPlaying == true
97
- }
98
-
99
- var audioMixingMode: AudioMixingMode = .auto
100
-
101
- if playingViews.isEmpty {
102
- return nil
103
- }
104
-
105
- for playerView in playingViews where (audioMixingMode.priority()) < playerView.audioMixingMode.priority() {
106
- audioMixingMode = playerView.audioMixingMode
107
- }
108
-
109
- return audioMixingMode
110
- }
111
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-libvlc-player",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "LibVLC Player for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",