简体   繁体   中英

Displaying subtitles using AVPlayerViewController with swift

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM