expo-libvlc-player 0.1.49 → 0.1.50

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 = '0.1.48'
4
+ version = '0.1.49'
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 "0.1.48"
30
+ versionName "0.1.49"
31
31
  consumerProguardFiles("proguard-rules.pro")
32
32
  }
33
33
  lintOptions {
@@ -1,9 +1,10 @@
1
1
  package expo.modules.libvlcplayer
2
2
 
3
- import com.facebook.react.bridge.ReadableMap
4
3
  import expo.modules.kotlin.modules.Module
5
4
  import expo.modules.kotlin.modules.ModuleDefinition
6
5
  import expo.modules.libvlcplayer.enums.AudioMixingMode
6
+ import expo.modules.libvlcplayer.records.Slave
7
+ import expo.modules.libvlcplayer.records.Tracks
7
8
 
8
9
  private const val BUFFERING_EVENT = "onBuffering"
9
10
  private const val PLAYING_EVENT = "onPlaying"
@@ -52,11 +53,11 @@ class LibVlcPlayerModule : Module() {
52
53
  view.options = options ?: ArrayList<String>()
53
54
  }
54
55
 
55
- Prop("slaves") { view: LibVlcPlayerView, slaves: ArrayList<ReadableMap>? ->
56
+ Prop("slaves") { view: LibVlcPlayerView, slaves: ArrayList<Slave>? ->
56
57
  view.slaves = slaves
57
58
  }
58
59
 
59
- Prop("tracks") { view: LibVlcPlayerView, tracks: ReadableMap? ->
60
+ Prop("tracks") { view: LibVlcPlayerView, tracks: Tracks? ->
60
61
  view.tracks = tracks
61
62
  }
62
63
 
@@ -2,12 +2,12 @@ package expo.modules.libvlcplayer
2
2
 
3
3
  import android.content.Context
4
4
  import android.net.Uri
5
- import com.facebook.react.bridge.ReadableMap
6
- import com.facebook.react.bridge.WritableMap
7
5
  import expo.modules.kotlin.AppContext
8
6
  import expo.modules.kotlin.viewevent.EventDispatcher
9
7
  import expo.modules.kotlin.views.ExpoView
10
8
  import expo.modules.libvlcplayer.enums.AudioMixingMode
9
+ import expo.modules.libvlcplayer.records.Slave
10
+ import expo.modules.libvlcplayer.records.Tracks
11
11
  import org.videolan.libvlc.LibVLC
12
12
  import org.videolan.libvlc.Media
13
13
  import org.videolan.libvlc.MediaPlayer
@@ -53,7 +53,7 @@ class LibVlcPlayerView(
53
53
  internal val onEndReached by EventDispatcher()
54
54
  internal val onEncounteredError by EventDispatcher()
55
55
  internal val onPositionChanged by EventDispatcher()
56
- internal val onParsedChanged by EventDispatcher<WritableMap>()
56
+ internal val onParsedChanged by EventDispatcher()
57
57
  internal val onBackground by EventDispatcher()
58
58
 
59
59
  init {
@@ -146,17 +146,16 @@ class LibVlcPlayerView(
146
146
  }
147
147
  }
148
148
 
149
- fun addPlayerSlave(slave: ReadableMap) {
150
- val source = slave.getString("source") ?: ""
151
- val type = slave.getString("type") ?: "item"
152
- val selected = false
153
-
149
+ fun addPlayerSlave(slave: Slave) {
150
+ val type = slave.type
154
151
  val slaveType =
155
152
  if (type == "subtitle") {
156
153
  IMedia.Slave.Type.Subtitle
157
154
  } else {
158
155
  IMedia.Slave.Type.Audio
159
156
  }
157
+ val source = slave.source
158
+ val selected = false
160
159
 
161
160
  try {
162
161
  mediaPlayer?.addSlave(slaveType, Uri.parse(source), selected)
@@ -168,11 +167,11 @@ class LibVlcPlayerView(
168
167
 
169
168
  fun addPlayerSlaves() {
170
169
  // Add in this specific order, otherwise subtitle slaves will be missing
171
- slaves?.filter { it.getString("type") == "subtitle" }?.forEach(::addPlayerSlave)
172
- slaves?.filter { it.getString("type") == "audio" }?.forEach(::addPlayerSlave)
170
+ slaves?.filter { it.type == "subtitle" }?.forEach(::addPlayerSlave)
171
+ slaves?.filter { it.type == "audio" }?.forEach(::addPlayerSlave)
173
172
  }
174
173
 
175
- var slaves: ArrayList<ReadableMap>? = null
174
+ var slaves: ArrayList<Slave>? = null
176
175
  set(value) {
177
176
  field = value
178
177
  addPlayerSlaves()
@@ -180,9 +179,9 @@ class LibVlcPlayerView(
180
179
 
181
180
  fun setPlayerTracks() {
182
181
  mediaPlayer?.let { player ->
183
- val audioTrack = tracks?.takeIf { it.hasKey("audio") }?.getInt("audio") ?: player.getAudioTrack()
184
- val videoTrack = tracks?.takeIf { it.hasKey("video") }?.getInt("video") ?: player.getVideoTrack()
185
- val spuTrack = tracks?.takeIf { it.hasKey("subtitle") }?.getInt("subtitle") ?: player.getSpuTrack()
182
+ val audioTrack = tracks?.audio ?: player.getAudioTrack()
183
+ val videoTrack = tracks?.video ?: player.getVideoTrack()
184
+ val spuTrack = tracks?.subtitle ?: player.getSpuTrack()
186
185
 
187
186
  player.setAudioTrack(audioTrack)
188
187
  player.setVideoTrack(videoTrack)
@@ -190,7 +189,7 @@ class LibVlcPlayerView(
190
189
  }
191
190
  }
192
191
 
193
- var tracks: ReadableMap? = null
192
+ var tracks: Tracks? = null
194
193
  set(value) {
195
194
  if (options.hasAudioTrackOption()) {
196
195
  val error = mapOf("error" to "Audio track selected via options")
@@ -1,6 +1,6 @@
1
1
  package expo.modules.libvlcplayer
2
2
 
3
- import com.facebook.react.bridge.Arguments
3
+ import expo.modules.libvlcplayer.records.Track
4
4
  import org.videolan.libvlc.interfaces.IMedia.Event
5
5
  import org.videolan.libvlc.interfaces.IMedia.EventListener
6
6
 
@@ -10,43 +10,37 @@ fun LibVlcPlayerView.setMediaListener() {
10
10
  EventListener { event ->
11
11
  when (event.type) {
12
12
  Event.ParsedChanged -> {
13
- val audioTracks = Arguments.createArray()
13
+ val audioTracks = mutableListOf<Track>()
14
14
  val audios = player.getAudioTracks()
15
15
 
16
16
  audios?.forEach { track ->
17
- val trackMap = Arguments.createMap()
18
- trackMap.putInt("id", track.id)
19
- trackMap.putString("name", track.name)
20
- audioTracks.pushMap(trackMap)
17
+ val trackObj = Track(id = track.id, name = track.name)
18
+ audioTracks.add(trackObj)
21
19
  }
22
20
 
23
- val videoTracks = Arguments.createArray()
21
+ val videoTracks = mutableListOf<Track>()
24
22
  val videos = player.getVideoTracks()
25
23
 
26
24
  videos?.forEach { track ->
27
- val trackMap = Arguments.createMap()
28
- trackMap.putInt("id", track.id)
29
- trackMap.putString("name", track.name)
30
- videoTracks.pushMap(trackMap)
25
+ val trackObj = Track(id = track.id, name = track.name)
26
+ videoTracks.add(trackObj)
31
27
  }
32
28
 
33
- val subtitleTracks = Arguments.createArray()
29
+ val subtitleTracks = mutableListOf<Track>()
34
30
  val subtitles = player.getSpuTracks()
35
31
 
36
32
  subtitles?.forEach { track ->
37
- val trackMap = Arguments.createMap()
38
- trackMap.putInt("id", track.id)
39
- trackMap.putString("name", track.name)
40
- subtitleTracks.pushMap(trackMap)
33
+ val trackObj = Track(id = track.id, name = track.name)
34
+ subtitleTracks.add(trackObj)
41
35
  }
42
36
 
43
37
  val video = player.getCurrentVideoTrack()
44
38
  val tracks =
45
- Arguments.createMap().apply {
46
- putArray("audio", audioTracks)
47
- putArray("video", videoTracks)
48
- putArray("subtitle", subtitleTracks)
49
- }
39
+ mapOf(
40
+ "audio" to audioTracks,
41
+ "video" to videoTracks,
42
+ "subtitle" to subtitleTracks,
43
+ )
50
44
  val ratio = player.getAspectRatio()
51
45
  val pLength = player.getLength()
52
46
  val length =
@@ -58,14 +52,14 @@ fun LibVlcPlayerView.setMediaListener() {
58
52
  val seekable = player.isSeekable()
59
53
 
60
54
  val videoInfo =
61
- Arguments.createMap().apply {
62
- putInt("width", video?.width ?: 0)
63
- putInt("height", video?.height ?: 0)
64
- putMap("tracks", tracks)
65
- putString("aspectRatio", ratio)
66
- putDouble("duration", length.toDouble())
67
- putBoolean("seekable", seekable)
68
- }
55
+ mapOf(
56
+ "width" to (video?.width ?: 0),
57
+ "height" to (video?.height ?: 0),
58
+ "tracks" to tracks,
59
+ "aspectRatio" to ratio,
60
+ "duration" to length.toDouble(),
61
+ "seekable" to seekable,
62
+ )
69
63
 
70
64
  onParsedChanged(videoInfo)
71
65
 
@@ -0,0 +1,11 @@
1
+ package expo.modules.libvlcplayer.records
2
+
3
+ import expo.modules.kotlin.records.Field
4
+ import expo.modules.kotlin.records.Record
5
+ import java.io.Serializable
6
+
7
+ class Slave(
8
+ @Field var source: String,
9
+ @Field var type: String,
10
+ ) : Record,
11
+ Serializable
@@ -0,0 +1,11 @@
1
+ package expo.modules.libvlcplayer.records
2
+
3
+ import expo.modules.kotlin.records.Field
4
+ import expo.modules.kotlin.records.Record
5
+ import java.io.Serializable
6
+
7
+ data class Track(
8
+ @Field val id: Int,
9
+ @Field val name: String,
10
+ ) : Record,
11
+ Serializable
@@ -0,0 +1,12 @@
1
+ package expo.modules.libvlcplayer.records
2
+
3
+ import expo.modules.kotlin.records.Field
4
+ import expo.modules.kotlin.records.Record
5
+ import java.io.Serializable
6
+
7
+ class Tracks(
8
+ @Field var audio: Int,
9
+ @Field var video: Int,
10
+ @Field var subtitle: Int,
11
+ ) : Record,
12
+ Serializable
@@ -41,11 +41,11 @@ public class LibVlcPlayerModule: Module {
41
41
  view.options = options ?? [String]()
42
42
  }
43
43
 
44
- Prop("slaves") { (view: LibVlcPlayerView, slaves: [[String: Any]]?) in
44
+ Prop("slaves") { (view: LibVlcPlayerView, slaves: [Slave]?) in
45
45
  view.slaves = slaves
46
46
  }
47
47
 
48
- Prop("tracks") { (view: LibVlcPlayerView, tracks: [String: Any]?) in
48
+ Prop("tracks") { (view: LibVlcPlayerView, tracks: Tracks?) in
49
49
  view.tracks = tracks
50
50
  }
51
51
 
@@ -117,14 +117,13 @@ class LibVlcPlayerView: ExpoView {
117
117
  }
118
118
  }
119
119
 
120
- func addPlayerSlave(_ slave: [String: Any]) {
121
- let source = slave["source"] as? String ?? ""
122
- let type = slave["type"] as? String ?? "item"
123
- let selected = false
124
-
120
+ func addPlayerSlave(_ slave: Slave) {
121
+ let source = slave.source
122
+ let type = slave.type
125
123
  let slaveType = type == "subtitle" ?
126
124
  VLCMediaPlaybackSlaveType.subtitle :
127
125
  VLCMediaPlaybackSlaveType.audio
126
+ let selected = false
128
127
 
129
128
  guard let url = URL(string: source) else {
130
129
  let error = ["error": "Invalid slave, \(type) could not be added"]
@@ -137,11 +136,11 @@ class LibVlcPlayerView: ExpoView {
137
136
 
138
137
  func addPlayerSlaves() {
139
138
  // Add in this specific order, otherwise subtitle slaves will be missing
140
- slaves?.filter { ($0["type"] as? String) == "subtitle" }.forEach { addPlayerSlave($0) }
141
- slaves?.filter { ($0["type"] as? String) == "audio" }.forEach { addPlayerSlave($0) }
139
+ slaves?.filter { $0.type == "subtitle" }.forEach { addPlayerSlave($0) }
140
+ slaves?.filter { $0.type == "audio" }.forEach { addPlayerSlave($0) }
142
141
  }
143
142
 
144
- var slaves: [[String: Any]]? {
143
+ var slaves: [Slave]? {
145
144
  didSet {
146
145
  addPlayerSlaves()
147
146
  }
@@ -159,7 +158,7 @@ class LibVlcPlayerView: ExpoView {
159
158
  player.currentVideoSubTitleIndex = Int32(videoSubTitleIndex)
160
159
  }
161
160
 
162
- var tracks: [String: Any]? {
161
+ var tracks: Tracks? {
163
162
  didSet {
164
163
  if options.hasAudioTrackOption() {
165
164
  let error = ["error": "Audio track selected via options"]
@@ -4,44 +4,38 @@ extension LibVlcPlayerView: VLCMediaDelegate {
4
4
  func mediaDidFinishParsing(_: VLCMedia) {
5
5
  guard let player = mediaPlayer else { return }
6
6
 
7
- var audioTracks: [[String: Any]] = []
7
+ var audioTracks: [Track] = []
8
8
 
9
9
  if let audios = player.audioTrackNames as? [String] {
10
10
  if let audioIndexes = player.audioTrackIndexes as? [NSNumber] {
11
- for (index, name) in audios.enumerated() {
11
+ for (index, trackName) in audios.enumerated() {
12
12
  let trackId = audioIndexes[index].intValue
13
- audioTracks.append([
14
- "id": trackId,
15
- "name": name,
16
- ])
13
+ let track = Track(id: trackId, name: trackName)
14
+ audioTracks.append(track)
17
15
  }
18
16
  }
19
17
  }
20
18
 
21
- var videoTracks: [[String: Any]] = []
19
+ var videoTracks: [Track] = []
22
20
 
23
21
  if let videos = player.videoTrackNames as? [String] {
24
22
  if let videoIndexes = player.videoTrackIndexes as? [NSNumber] {
25
- for (index, name) in videos.enumerated() {
23
+ for (index, trackName) in videos.enumerated() {
26
24
  let trackId = videoIndexes[index].intValue
27
- videoTracks.append([
28
- "id": trackId,
29
- "name": name,
30
- ])
25
+ let track = Track(id: trackId, name: trackName)
26
+ videoTracks.append(track)
31
27
  }
32
28
  }
33
29
  }
34
30
 
35
- var subtitleTracks: [[String: Any]] = []
31
+ var subtitleTracks: [Track] = []
36
32
 
37
33
  if let subtitles = player.videoSubTitlesNames as? [String] {
38
34
  if let subtitleIndexes = player.videoSubTitlesIndexes as? [NSNumber] {
39
- for (index, name) in subtitles.enumerated() {
35
+ for (index, trackName) in subtitles.enumerated() {
40
36
  let trackId = subtitleIndexes[index].intValue
41
- subtitleTracks.append([
42
- "id": trackId,
43
- "name": name,
44
- ])
37
+ let track = Track(id: trackId, name: trackName)
38
+ subtitleTracks.append(track)
45
39
  }
46
40
  }
47
41
  }
@@ -0,0 +1,9 @@
1
+ import ExpoModulesCore
2
+
3
+ struct Slave: Record {
4
+ @Field
5
+ var source: String
6
+
7
+ @Field
8
+ var type: String
9
+ }
@@ -0,0 +1,14 @@
1
+ import ExpoModulesCore
2
+
3
+ struct Track: Record {
4
+ @Field
5
+ var id: Int
6
+
7
+ @Field
8
+ var name: String
9
+
10
+ init(id: Int, name: String) {
11
+ self.id = id
12
+ self.name = name
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ import ExpoModulesCore
2
+
3
+ struct Tracks: Record {
4
+ @Field
5
+ var audio: Int
6
+
7
+ @Field
8
+ var video: Int
9
+
10
+ @Field
11
+ var subtitle: Int
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-libvlc-player",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "LibVLC Player for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",