mhergon / avplayerviewcontroller-subtitles Goto Github PK
View Code? Open in Web Editor NEWEasy way to show SRT files on AVPlayerViewController
License: Apache License 2.0
Easy way to show SRT files on AVPlayerViewController
License: Apache License 2.0
I am not sure which settings i have to do for displaying captions in fullscreen mode.
Subtitles/Captions are working fine in normal play. But it not displaying in fullscreen(picture-in-picture) mode.
What am i missing here?
2016-07-03 16:41:33.402 Dog Trainer[6570:2093417] *** Terminating app due to uncaught 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)-|
^'
*** First throw call stack:
(0x180b3edb0 0x1801a3f80 0x1815f898c 0x18147a680 0x181479490 0x181479070 0x100138394 0x100137484 0x100138920 0x1000bbd48 0x1000bc0ac 0x185c9cc40 0x185cb50d0 0x185e4fe5c 0x185d5be40 0x185d5bb1c 0x185d5ba84 0x185c981e4 0x18362a994 0x1836255d0 0x183625490 0x183624ac0 0x183624820 0x185c8e5f8 0x180af4728 0x180af24cc 0x180af28fc 0x180a1cc50 0x182304088 0x185d06088 0x1000be894 0x1805ba8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
navigationItem.title = command?.name
if let c = command, videoURL = NSBundle.mainBundle().URLForResource(c.movieFilename, withExtension: "mp4") {
let player = AVPlayer(URL: videoURL)
playerController.player = player
if let subs = NSBundle.mainBundle().URLForResource(c.subtitlesFilename, withExtension: "srt") {
playerController.addSubtitles().open(file: subs)
}
if let pv = playerView {
pv.addSubview(playerController.view)
playerController.view.frame = pv.frame
}
}
we need to add multiple language other than english.But when i put a file which is not encoding properly
Hey! First of all, thank you for the extension, it is really simple and adds a lot of value.
This is more of an improvement than an issue actually, but happens when you are using a custom view for the player controller that the extension may crash depending on your implementation.
One common scenario on this is when you try to keep playing videos while in background and you pick one specific solution of the two provided by Apple here
In this scenarios, the extension may crash since it uses the contentOverlayView
in order to add the subtitleLabel
. If the contentOverlayView
is nil, the app will crash trying to figure out the superview when creating constraints with the visual format specified.
Based on this, I changed the following
fileprivate func addSubtitleLabel() {
guard let _ = subtitleLabel else {
// ... label setup
contentOverlayView?.addSubview(subtitleLabel!)
// ... continue constraints
}
with something a little bit more defensive like:
fileprivate func addSubtitleLabel() {
guard let _ = subtitleLabel else {
// ... label setup
if contentOverlayView != nil {
contentOverlayView?.addSubview(subtitleLabel!)
} else {
view.addSubview(subtitleLabel!)
}
// ... continue constraints
}
Hope this helps
Please help !!!
How can I seek, win or un-wina video?
Thank so much!
I was watching star wars and there were <i>
tags that showed up (presuming they should be parsed as italics) and in despicable me there is <font>
tags with color attributes that arent parsed either. Attached despicable me srt
minions-yify-70900.zip
Would be great to have support for on/off subtitles & cc from the default AVPlayerViewController UI.
I'll give a try to implement it, hope is possbile.
Hello @mhergon,
any changes to update to Swift 3.0?
thanks :)
The library doesn't show subtitles at the last minute
I tried more than .srt and more than movie
I noticed that the last minute doesn't appear
Objective-C can be imported and used in the project?
@mhergon Would you be so kind to cut a new release and update the cocoapods for it? Would be happy to help wherever you see fit.
Is you lib supporting tvOS? You cocoaspec says no, but AVPlayer is available on tvOS too.
Please support with XML subtitle file
<text start="14.91" dur="6.43">Jon Alger: Good afternoon everyone. Thank
you. I&#39;m Jon Alger, president of James Madison</text><text start="21.34" dur="5.93">University and it&#39;s my great pleasure to welcome
you to this fifth event of the Madison Vision</text><text start="27.27" dur="5.87">Series. Through the Madison Vision Fund we
are proud to sponsor the Madison Vision Series
Could you also provide an example how to download the srt files from youtube?
I know this is out of scope - but many users of your app could use it.
Code crashes in case when text is empty
Patch:
---
Subtitles.swift | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/Subtitles.swift b/Subtitles.swift
index b9541b9..c8d0480 100644
--- a/Subtitles.swift
+++ b/Subtitles.swift
@@ -169,8 +169,15 @@ public extension AVPlayerViewController {
scanner.scanDouble(&c)
let toTime = (h * 3600.0) + (m * 60.0) + s + (c / 1000.0)
+ let range = NSMakeRange(0, to.range.location + to.range.length + 1)
+
+ // Check if text is not empty
+ if (group as NSString).length - range.length <= 0 {
+ continue
+ }
+
// Get text
- let text = (group as NSString).stringByReplacingCharactersInRange(NSMakeRange(0, to.range.location + to.range.length + 1), withString: "")
+ let text = (group as NSString).stringByReplacingCharactersInRange(range, withString: "")
// Create final object
let final = NSMutableDictionary()
--
2.6.2
Might change Subtitles init method and use a do try catch block. My app crashed when contents of file for URL path was unreadable.
do { // Get string let string = try String(contentsOf: filePath, encoding: encoding) // Parse string parsedPayload = Subtitles.parseSubRip(string) } catch { print(error) }
Hi, thank you for this awesome library. On iOS 11, subtitle position which is top-left corner is wrong. Could you please fix it?
I was wondering how can i change the text size to a smaller size.
I found this code , but i could not achieve into smaller text without having some cropped sub text.
// Adjust size let rect = (label.text! as NSString).boundingRect(with: CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName : label.font!], context: nil) subtitleLabelHeightConstraint?.constant = rect.size.height + 5.0
I'm facing a problem with the iOS 11.0 and 11.1. In both cases the system totally avoid the subtitleLabel constraints, it's like none of them were been implemented.
Have you guys ever faced this issue?
Please check your label with utf8 string. I put this code
subtitleLabel?.lineBreakMode = .ByWordWrapping
and it work perfect
Please help!!!
I dont want to download subtitle file to bundle and I want to get subtitle file from server (https://...)
Please help me with other way
Thank sir!!!
let subtitleFile = Bundle.main.path(forResource: "1", ofType: "srt")
subtitleURL = URL(fileURLWithPath: subtitleFile!)
parser = Subtitles(file: subtitleURL!, encoding: .utf8)
I am using this library to get the captions from youtube url while parsing the XML caption youtube provides.
Creating a NSdictionary and using the NSDictionary in the library.
Should i make a pull request for this to be able to use a NSDictionary ?
Hi ,
just wondering if you guys support WEBVTT subtitles as I have several videos with VTT subtitles (see attachments ) but they won't show up.
Appreciate your help :)
I have encountered the same issue with #42 for some srt files, following srt file is a sample file.
https://drive.google.com/file/d/1d9kmpLmfrb1hfQoywNNDPhezdzSKDLPQ/view.
The parseSubRip func, can only get the subtitles index to 1158 01:36:08,513 --> 01:36:10,878, the index 1159~1170 are ignored.
'scanDouble' was deprecated in iOS 13
scanString(_:into:)
scanner.scanDouble(&h)
scanner.scanString(":", into: nil)
scanner.scanDouble(&m)
scanner.scanString(":", into: nil)
scanner.scanDouble(&s)
scanner.scanString(",", into: nil)
scanner.scanDouble(&c)
fixing this to doesn't show subtitles
Hi is it possible to play the subtitles without play (and show) any video
Just add it on an empty UIView
Thanks!
I found the func parseSubRip
let regexStr = "(?m)(^[0-9]+)([\s\S]*?)(?=\n\n)"
let regex = try NSRegularExpression(pattern: regexStr, options: .caseInsensitive)
let matches = regex.matches(in: payload, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSMakeRange(0, payload.characters.count))
the matches will lost last lines text
defaul srt have 6 lines
but only match 5 lines
how to fix this bug?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.