Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

feat: add None option in the caption list to deselect caption language #1773

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Source/CutomePlayer/OEXVideoPlayerSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

private let cellId = "CustomCell"
let captionLanguageNone = "none"

public typealias RowType = (title: String, value: Any)
public struct OEXVideoPlayerSetting {
Expand Down Expand Up @@ -66,20 +67,23 @@ class VideoPlayerSettings : NSObject {
rows.append(item)
}
}

if !rows.isEmpty {
rows.append(RowType(title: Strings.none, value: captionLanguageNone))
}

let cc = OEXVideoPlayerSetting(title: Strings.videoSettingClosedCaptions, rows: rows, isSelected: { (row) -> Bool in
var selected = false
if let selectedLanguage:String = OEXInterface.getCCSelectedLanguage() {
let lang = rows[row].value as! String
selected = selectedLanguage == lang

var selectedLanguage = OEXInterface.getCCSelectedLanguage() ?? captionLanguageNone
if selectedLanguage.isEmpty {
selectedLanguage = captionLanguageNone
}
let lang = rows[row].value as? String ?? captionLanguageNone
selected = selectedLanguage == lang
return selected
}) {[weak self] value in
var language : String = value as! String
if language == OEXInterface.getCCSelectedLanguage() && language != "" {
language = ""
}
self?.delegate?.setCaption(language: language)
self?.delegate?.setCaption(language: value as? String ?? "")
}
return [cc, speeds]
} else {
Expand Down
12 changes: 11 additions & 1 deletion Source/CutomePlayer/TranscriptManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ class TranscriptManager: NSObject {

private var captionURL: String {
var url: String = ""
if let ccSelectedLanguage = OEXInterface.getCCSelectedLanguage(), let transcriptURL = video.summary?.transcripts?[ccSelectedLanguage] as? String, !ccSelectedLanguage.isEmpty, !transcriptURL.isEmpty{
let devicelangue = Locale.current.languageCode ?? ""

if let ccSelectedLanguage = OEXInterface.getCCSelectedLanguage(), let transcriptURL = video.summary?.transcripts?[ccSelectedLanguage] as? String, !ccSelectedLanguage.isEmpty, !transcriptURL.isEmpty, ccSelectedLanguage != captionLanguageNone {
url = transcriptURL
}
else if let transcriptURL = video.summary?.transcripts?[devicelangue] as? String,!devicelangue.isEmpty, !transcriptURL.isEmpty {
// if no language is selected, give preference to device language
url = transcriptURL
}
else if let transcriptURL = video.summary?.transcripts?["en"] as? String, !transcriptURL.isEmpty {
// if no language is selected, and transcripts are not available for device langue, look for english
url = transcriptURL
}
else if let transcriptURL = video.summary?.transcripts?.values.first as? String {
Expand Down
9 changes: 7 additions & 2 deletions Source/CutomePlayer/VideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class VideoPlayer: UIViewController,VideoPlayerControlsDelegate,TranscriptManage
transcriptManager = TranscriptManager(environment: environment, video: video)
transcriptManager?.delegate = self

if let ccSelectedLanguage = OEXInterface.getCCSelectedLanguage(), let transcriptURL = video.summary?.transcripts?[ccSelectedLanguage] as? String, !ccSelectedLanguage.isEmpty, !transcriptURL.isEmpty {
if let ccSelectedLanguage = OEXInterface.getCCSelectedLanguage(), let transcriptURL = video.summary?.transcripts?[ccSelectedLanguage] as? String, !ccSelectedLanguage.isEmpty, !transcriptURL.isEmpty, ccSelectedLanguage != captionLanguageNone {
controls?.activateSubTitles()
}
}
Expand Down Expand Up @@ -660,9 +660,14 @@ class VideoPlayer: UIViewController,VideoPlayerControlsDelegate,TranscriptManage
}

func captionUpdate(playerControls: VideoPlayerControls, language: String) {
let alreadySelectedLanguage = OEXInterface.getCCSelectedLanguage() ?? ""
OEXInterface.setCCSelectedLanguage(language)
if language.isEmpty {

if alreadySelectedLanguage == language { return }

if language == captionLanguageNone {
playerControls.deAvtivateSubTitles()
transcriptManager?.loadTranscripts()
}
else {
transcriptManager?.loadTranscripts()
Expand Down
2 changes: 2 additions & 0 deletions Source/ar.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/de.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/en.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/es-419.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/fr.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/he.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/ja.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/pt-BR.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/tr.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/vi.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
2 changes: 2 additions & 0 deletions Source/zh-Hans.lproj/Localizable-2.strings
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"MY_COURSES"="My courses";
/*Title My programs*/
"MY_PROGRAMS"="My programs";
/* None option in the caption list to de select caption language*/
"NONE"="None";
Loading