5 // Created by Kevin Jantzer on 12/30/15.
13 var resource: FRResource
14 var data = [FRSmilElement]()
16 init(resource: FRResource){
17 self.resource = resource;
23 return self.resource.id;
26 func href() -> String {
27 return self.resource.href;
30 // MARK: - data methods
33 Returns a smil <par> tag which contains info about parallel audio and text to be played
35 func parallelAudioForFragment(_ fragment: String!) -> FRSmilElement! {
36 return findParElement(forTextSrc: fragment, inData: data)
39 fileprivate func findParElement(forTextSrc src:String!, inData _data:[FRSmilElement]) -> FRSmilElement! {
42 // if its a <par> (parallel) element and has a <text> node with the matching fragment
43 if( el.name == "par" && (src == nil || el.textElement().attributes["src"]?.contains(src) != false ) ){
46 // if its a <seq> (sequence) element, it should have children (<par>)
47 }else if el.name == "seq" && el.children.count > 0 {
48 let parEl = findParElement(forTextSrc: src, inData: el.children)
49 if parEl != nil { return parEl }
56 Returns a smil <par> element after the given fragment
58 func nextParallelAudioForFragment(_ fragment: String) -> FRSmilElement! {
59 return findNextParElement(forTextSrc: fragment, inData: data)
62 fileprivate func findNextParElement(forTextSrc src:String!, inData _data:[FRSmilElement]) -> FRSmilElement! {
66 if foundPrev { return el }
68 // if its a <par> (parallel) element and has a <text> node with the matching fragment
69 if( el.name == "par" && (src == nil || el.textElement().attributes["src"]?.contains(src) != false) ){
72 // if its a <seq> (sequence) element, it should have children (<par>)
73 }else if el.name == "seq" && el.children.count > 0 {
74 let parEl = findNextParElement(forTextSrc: src, inData: el.children)
75 if parEl != nil { return parEl }
82 func childWithName(_ name:String) -> FRSmilElement! {
84 if( el.name == name ){
91 func childrenWithNames(_ name:[String]) -> [FRSmilElement]! {
92 var matched = [FRSmilElement]()
94 if( name.contains(el.name) ){
101 func childrenWithName(_ name:String) -> [FRSmilElement]! {
102 return childrenWithNames([name])
107 Holds array of `FRSmilFile`
109 class FRSmils: NSObject {
110 var basePath : String!
111 var smils = [String: FRSmilFile]()
114 Adds a smil to the smils.
116 func add(_ smil: FRSmilFile) {
117 self.smils[smil.resource.href] = smil
121 Gets the resource with the given href.
123 func findByHref(_ href: String) -> FRSmilFile? {
124 for smil in smils.values {
125 if smil.resource.href == href {
133 Gets the resource with the given id.
135 func findById(_ ID: String) -> FRSmilFile? {
136 for smil in smils.values {
137 if smil.resource.id == ID {