GithubHelp home page GithubHelp logo

mhergon / avplayerviewcontroller-subtitles Goto Github PK

View Code? Open in Web Editor NEW
263.0 263.0 67.0 17.38 MB

Easy way to show SRT files on AVPlayerViewController

License: Apache License 2.0

Ruby 2.74% Swift 97.26%

avplayerviewcontroller-subtitles's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avplayerviewcontroller-subtitles's Issues

Subtitles/Captions not working in fullscreen mode

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?

crash

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

schermata 2016-07-03 alle 16 43 33

    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
        }
    }

Crash when using custom player view

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

Not all tags are parsed correctly.

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

Doesn't show last minutes

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

Generate New Release

@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.

support tvOS

Is you lib supporting tvOS? You cocoaspec says no, but AVPlayer is available on tvOS too.

XML subtitle

Please support with XML subtitle file

<text start="14.91" dur="6.43">Jon Alger: Good afternoon everyone. Thank
you. I&amp;#39;m Jon Alger, president of James Madison</text><text start="21.34" dur="5.93">University and it&amp;#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

Download SRT Files

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.

Crash

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


Initializing Subtitles needs modification

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) }

iOS 11 - Subtitle position

Hi, thank you for this awesome library. On iOS 11, subtitle position which is top-left corner is wrong. Could you please fix it?

subtitleLabel.backgroundColor layout problem

`
// Change text properties

moviePlayer.subtitleLabel?.textColor = UIColor.red
moviePlayer.subtitleLabel?.backgroundColor = UIColor.black
`

when using backgroundColor there is some problem when the subtitle is not active.
Any idea why this is happening?

simulator screen shot 30 jun 2017 00 39 31
simulator screen shot 30 jun 2017 00 39 38

How to change subtitles text size

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

Problem in iOS 11.0 and 11.1

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?

Text not fit UILabel

Please check your label with utf8 string. I put this code
subtitleLabel?.lineBreakMode = .ByWordWrapping
and it work perfect

Remote subtitle

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)

add NSDictionary subtitles support

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 ?

scanner deprecated since iOS 13

'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

func parseSubRip hava bug

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.