-1

I am new to Swift and video streaming. I am trying to play videos in AppleTV. Did some one try to add subtitles with AVPlayerViewController in swift from an external srt file. I am trying to do the same using code from here: https://github.com/mhergon/MPMoviePlayerController-Subtitles.

I changed the code to suit my requirements, but it is throwing an exception:

NSInvalidArgumentException', reason: 'Unable to parse constraint format: Unable to interpret '|' character, because the related view doesn't have a superview H:|-(20)-[l]-(20)-|

At this point in the Subtitles.swift file:

var constraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(20)-[l]-(20)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["l" : subtitleLabel!])
    subtitleContainer?.addConstraints(constraints)
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
Enmud
  • 83
  • 1
  • 1
  • 9

1 Answers1

0

The error message complains, that there is no superview. Looking at the source I would assume that the container is not properly set. This leads to subtitleLabel not being child of a super view and that makes the constraint fail.

Rainer Schwarze
  • 4,725
  • 1
  • 27
  • 49
  • Yes you are right container is not being set in getContainer(). I am not sure why this not set. I don't understand how that c.tag == 1006 is true when using MPMoviePlayerController and not when using AVPLayerViewController. – Enmud Dec 23 '15 at 03:05
  • @Enmud Can you show your code which sets up your views? – Rainer Schwarze Dec 23 '15 at 07:21
  • Thanks for your reply. In this below code subtitle container is being set. But i didn't find anywhere the tag which is referred in the below code. You can check the same code in github repository (Link in question) . private func getContainer() { for a in view.subviews { for b in a.subviews { for c in b.subviews { if c.tag == 1006 { subtitleContainer = c } } } } } – Enmud Dec 23 '15 at 09:10
  • @Enmud Did you set the tag to 1006 for the view which shall be the container view? I assume that an xib file or a storyboard and in there you likely need to mark a view as the container view. The github code seems to expect that the container view has a tag value of 1006. – Rainer Schwarze Dec 23 '15 at 09:50
  • I didn't set this also I am sure that there is no view with tag 1006. But surprisingly the container is set in the original code from repository and shows subtitles. I am confused. You can debug original repository code where this is set. – Enmud Dec 23 '15 at 10:17