Skip to content

Commit 1100442

Browse files
committed
chore: add setResume and setSource
1 parent 12cbd0b commit 1100442

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

ios/RCTVLCPlayer.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class RCTVLCPlayer : UIView {
8282

8383
@objc
8484
func setResume(_ autoplay: Bool) {
85+
if _player != nil {
86+
_release()
87+
}
88+
89+
playMedia(_source)
8590

8691
}
8792

@@ -95,6 +100,17 @@ class RCTVLCPlayer : UIView {
95100
_source = source
96101
_videoInfo = nil
97102

103+
playMedia(source)
104+
105+
if _subtitleUri != nil, let uri = URL(string: _subtitleUri) {
106+
_player.addPlaybackSlave(uri, type: .subtitle, enforce: true)
107+
}
108+
109+
self.play()
110+
111+
}
112+
113+
private func playMedia(_ source: NSDictionary) {
98114
guard let uri = source["uri"] as? String else { return }
99115
let autoPlay = source["autoPlay"] as? Bool ?? true
100116

@@ -110,16 +126,24 @@ class RCTVLCPlayer : UIView {
110126
media.addOptions(initOptions)
111127
}
112128

113-
let options = ["rtsp-tcp": "1"]
114-
media.addOptions(options)
115-
116129
_player.media = media
117130
_player.delegate = self
118131

119132
try? AVAudioSession.sharedInstance().setActive(false, options: AVAudioSession.SetActiveOptions.notifyOthersOnDeactivation)
133+
print("Autoplay: \(autoPlay)")
120134

121-
self.play()
135+
self.onVideoLoad?([
136+
"target": self.reactTag
137+
])
138+
}
139+
140+
@objc
141+
func setSubtitleUri(_ subtitleUri: String) {
142+
_subtitleUri = subtitleUri
122143

144+
if _player != nil, let subtitle = URL(string: subtitleUri) {
145+
_player.addPlaybackSlave(subtitle, type: .subtitle, enforce: true)
146+
}
123147
}
124148

125149
@objc

ios/RCTVLCPlayerManager.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
@interface RCT_EXTERN_MODULE(RCTVLCPlayerManager, RCTViewManager)
44

5-
RCT_EXPORT_VIEW_PROPERTY(color, NSString)
6-
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
7-
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL)
5+
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary);
6+
RCT_EXPORT_VIEW_PROPERTY(subtitleUri, NSString);
7+
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
88
RCT_EXPORT_VIEW_PROPERTY(seek, float);
99
RCT_EXPORT_VIEW_PROPERTY(rate, float);
1010
RCT_EXPORT_VIEW_PROPERTY(resume, BOOL);
11-
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL);
1211
RCT_EXPORT_VIEW_PROPERTY(snapshotPath, NSString);
12+
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL);
1313
RCT_EXPORT_VIEW_PROPERTY(audioTrack, int);
1414
RCT_EXPORT_VIEW_PROPERTY(textTrack, int);
1515

16+
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
1617
RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTDirectEventBlock);
1718
RCT_EXPORT_VIEW_PROPERTY(onVideoPaused, RCTDirectEventBlock);
1819
RCT_EXPORT_VIEW_PROPERTY(onVideoStopped, RCTDirectEventBlock);

0 commit comments

Comments
 (0)