Fix subtitle bug when stream includes embedded
This commit is contained in:
parent
5e5e9f7b05
commit
ee0f46576e
|
@ -94,7 +94,7 @@ struct NextUpView: View {
|
||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
Text("S\(String(item.ParentIndexNumber ?? 0))E\(String(item.IndexNumber ?? 0))")
|
Text("S\(String(item.ParentIndexNumber ?? 0)):E\(String(item.IndexNumber ?? 0))")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct Subtitle {
|
||||||
var name: String;
|
var name: String;
|
||||||
var id: Int32;
|
var id: Int32;
|
||||||
var url: URL;
|
var url: URL;
|
||||||
|
var delivery: String;
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
@ -55,7 +56,15 @@ struct PlayerDemo: View {
|
||||||
@State private var captionConfiguration: Bool = false {
|
@State private var captionConfiguration: Bool = false {
|
||||||
didSet {
|
didSet {
|
||||||
if(captionConfiguration == false) {
|
if(captionConfiguration == false) {
|
||||||
vlcplayer.play()
|
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
||||||
|
vlcplayer.pause()
|
||||||
|
usleep(10000);
|
||||||
|
vlcplayer.play()
|
||||||
|
usleep(10000);
|
||||||
|
vlcplayer.pause()
|
||||||
|
usleep(10000);
|
||||||
|
vlcplayer.play()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -221,14 +230,12 @@ struct PlayerDemo: View {
|
||||||
let streamURL: URL = URL(string: "\(globalData.server?.baseURI ?? "")\((json["MediaSources"][0]["TranscodingUrl"].string ?? "").replacingOccurrences(of: "master.m3u8", with: "main.m3u8"))")!
|
let streamURL: URL = URL(string: "\(globalData.server?.baseURI ?? "")\((json["MediaSources"][0]["TranscodingUrl"].string ?? "").replacingOccurrences(of: "master.m3u8", with: "main.m3u8"))")!
|
||||||
print(streamURL);
|
print(streamURL);
|
||||||
let item = PlaybackItem(videoType: VideoType.hls, videoUrl: streamURL, subtitles: [])
|
let item = PlaybackItem(videoType: VideoType.hls, videoUrl: streamURL, subtitles: [])
|
||||||
var SubIndex: Int32 = 2;
|
let disableSubtitleTrack = Subtitle(name: "Disabled", id: -1, url: URL(string: "https://example.com")!, delivery: "Embed")
|
||||||
let disableSubtitleTrack = Subtitle(name: "Disabled", id: -1, url: URL(string: "https://example.com")!)
|
|
||||||
_subtitles.wrappedValue.append(disableSubtitleTrack);
|
_subtitles.wrappedValue.append(disableSubtitleTrack);
|
||||||
for (_,stream):(String, JSON) in json["MediaSources"][0]["MediaStreams"] {
|
for (_,stream):(String, JSON) in json["MediaSources"][0]["MediaStreams"] {
|
||||||
if(stream["Type"].string == "Subtitle") {
|
if(stream["Type"].string == "Subtitle") {
|
||||||
let deliveryUrl = URL(string: "\(globalData.server?.baseURI ?? "")\(stream["DeliveryUrl"].string ?? "")")!
|
let deliveryUrl = URL(string: "\(globalData.server?.baseURI ?? "")\(stream["DeliveryUrl"].string ?? "")")!
|
||||||
let subtitle = Subtitle(name: stream["DisplayTitle"].string ?? "", id: SubIndex, url: deliveryUrl)
|
let subtitle = Subtitle(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0), url: deliveryUrl, delivery: stream["DeliveryMethod"].string ?? "")
|
||||||
SubIndex+=1;
|
|
||||||
_subtitles.wrappedValue.append(subtitle);
|
_subtitles.wrappedValue.append(subtitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,14 +247,13 @@ struct PlayerDemo: View {
|
||||||
print("Direct play of item \(item.Name)")
|
print("Direct play of item \(item.Name)")
|
||||||
let streamURL: URL = URL(string: "\(globalData.server?.baseURI ?? "")/Videos/\(item.Id)/stream.mp4?Static=true&mediaSourceId=\(item.Id)&deviceId=\(globalData.user?.device_uuid ?? "")&api_key=\(globalData.authToken)&Tag=\(json["MediaSources"][0]["ETag"])")!;
|
let streamURL: URL = URL(string: "\(globalData.server?.baseURI ?? "")/Videos/\(item.Id)/stream.mp4?Static=true&mediaSourceId=\(item.Id)&deviceId=\(globalData.user?.device_uuid ?? "")&api_key=\(globalData.authToken)&Tag=\(json["MediaSources"][0]["ETag"])")!;
|
||||||
let item = PlaybackItem(videoType: VideoType.direct, videoUrl: streamURL, subtitles: [])
|
let item = PlaybackItem(videoType: VideoType.direct, videoUrl: streamURL, subtitles: [])
|
||||||
var SubIndex: Int32 = 2;
|
let disableSubtitleTrack = Subtitle(name: "Disabled", id: -1, url: URL(string: "https://example.com")!, delivery: "Embed")
|
||||||
let disableSubtitleTrack = Subtitle(name: "Disabled", id: -1, url: URL(string: "https://example.com")!)
|
|
||||||
_subtitles.wrappedValue.append(disableSubtitleTrack);
|
_subtitles.wrappedValue.append(disableSubtitleTrack);
|
||||||
for (_,stream):(String, JSON) in json["MediaSources"][0]["MediaStreams"] {
|
for (_,stream):(String, JSON) in json["MediaSources"][0]["MediaStreams"] {
|
||||||
if(stream["Type"].string == "Subtitle") {
|
if(stream["Type"].string == "Subtitle") {
|
||||||
|
print("Found subtitle track with title \(stream["DisplayTitle"].string ?? "") Delivery method: \(stream["DeliveryMethod"].string ?? "")")
|
||||||
let deliveryUrl = URL(string: "\(globalData.server?.baseURI ?? "")\(stream["DeliveryUrl"].string ?? "")")!
|
let deliveryUrl = URL(string: "\(globalData.server?.baseURI ?? "")\(stream["DeliveryUrl"].string ?? "")")!
|
||||||
let subtitle = Subtitle(name: stream["DisplayTitle"].string ?? "", id: SubIndex, url: deliveryUrl)
|
let subtitle = Subtitle(name: stream["DisplayTitle"].string ?? "", id: Int32(stream["Index"].int ?? 0), url: deliveryUrl, delivery: stream["DeliveryMethod"].string ?? "")
|
||||||
SubIndex+=1;
|
|
||||||
_subtitles.wrappedValue.append(subtitle);
|
_subtitles.wrappedValue.append(subtitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,14 +412,20 @@ struct PlayerDemo: View {
|
||||||
.overrideViewPreference(.dark)
|
.overrideViewPreference(.dark)
|
||||||
.popover( isPresented: self.$captionConfiguration, arrowEdge: .bottom) {
|
.popover( isPresented: self.$captionConfiguration, arrowEdge: .bottom) {
|
||||||
NavigationView() {
|
NavigationView() {
|
||||||
Form() {
|
VStack() {
|
||||||
Picker("Closed Captions", selection: $selectedCaptionTrack) {
|
Form() {
|
||||||
ForEach(subtitles, id: \.id) { caption in
|
Picker("Closed Captions", selection: $selectedCaptionTrack) {
|
||||||
Text(caption.name).tag(caption.id)
|
ForEach(subtitles, id: \.id) { caption in
|
||||||
|
Text(caption.name).tag(caption.id)
|
||||||
|
}
|
||||||
|
}.onChange(of: selectedCaptionTrack) { track in
|
||||||
|
vlcplayer.currentVideoSubTitleIndex = track;
|
||||||
}
|
}
|
||||||
}.onChange(of: selectedCaptionTrack) { track in
|
|
||||||
vlcplayer.currentVideoSubTitleIndex = track;
|
|
||||||
}
|
}
|
||||||
|
Text("Subtitles may take a few moments to appear once selected.")
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
.navigationBarTitle("Audio & Captions", displayMode: .inline)
|
.navigationBarTitle("Audio & Captions", displayMode: .inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|
|
@ -64,7 +64,7 @@ class PlayerUIView: UIView, VLCMediaPlayerDelegate {
|
||||||
mediaPlayer.wrappedValue.stop()
|
mediaPlayer.wrappedValue.stop()
|
||||||
mediaPlayer.wrappedValue.media = VLCMedia(url: self.url.wrappedValue.videoUrl)
|
mediaPlayer.wrappedValue.media = VLCMedia(url: self.url.wrappedValue.videoUrl)
|
||||||
self.url.wrappedValue.subtitles.forEach() { sub in
|
self.url.wrappedValue.subtitles.forEach() { sub in
|
||||||
if(sub.id != -1) {
|
if(sub.id != -1 && sub.delivery == "External") {
|
||||||
mediaPlayer.wrappedValue.addPlaybackSlave(sub.url, type: .subtitle, enforce: false)
|
mediaPlayer.wrappedValue.addPlaybackSlave(sub.url, type: .subtitle, enforce: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue