Skip to content

swagatnayak/SNAVPlayerSubtitles

Repository files navigation

SNAVPlayerSubtitles

CI Status Version License Platform Quality Gate Status

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

pod install

Requirements

Swift 4 and above Xcode 11

Installation

SNAVPlayerSubtitles is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SNAVPlayerSubtitles'

Then got to your project root folder and run

pod install

Uses

For AVPlayerViewController

// Declare AVPlayerViewController
var playerViewController: AVPlayerViewController = AVPlayerViewController()


//MARK: - Enter your media url here (i,e .mp4, .m3u8(Hls))
let videoURL = URL(string: "<Enter your media url here>")
let subtitleURL = URL(string: "<Enter your subtitle url here>")

// Declare AVPlayer and add to AVPlayerViewController
let player = AVPlayer(url: videoURL)
self.playerViewController.player = player

------------------------------------------------

// Now to add subtitle

//MARK: - For Remote url
self.playerViewController.addSubtitles(textStyle: .CLEAR_BACKGROUND).open(fileFromRemote: subtitleURL,type: .VTT)

//MARK: - For local file
self.playerViewController.addSubtitles(textStyle: .CLEAR_BACKGROUND).open(fileFromLocal: "",type: .VTT)
/*
NOTE : 
    textStyle -> Optional (default -> .CLEAR_BACKGROUND)
    type -> Required (Must be .SRT or .VTT)
*/

// Now Play media
self.playerViewController.player.play()

For Directly use in AVPlayer

//Enter your media url here (i,e .mp4, .m3u8(Hls))
let videoURL = URL(string: "<Enter your media url here>")

//Enter your subtitle url here)
let subtitleURL = URL(string: "<Enter your subtitle url here>")

// Declare AVPlayer and add to AVPlayerViewController
let player = AVPlayer(url: videoURL)

------------------------------------------------

// Now to add subtitle

//MARK: - For Remote url
self.player.addSubtitles(textStyle: .CLEAR_BACKGROUND).open(fileFromRemote: subtitleURL,type: .VTT)

//MARK: - For local file
self.player.addSubtitles(textStyle: .CLEAR_BACKGROUND).open(fileFromLocal: "",type: .VTT)

/*
NOTE : 
    textStyle -> Optional (default -> .CLEAR_BACKGROUND)
    type -> Required (Must be .SRT or .VTT)
*/

// Now Play media
self.player.play()

Property

Property

Property Remark Accepted values
.addSubtitles(textStyle: .CLEAR_BACKGROUND) textStyle -> Optional
Default value = .CLEAR_BACKGROUND
.CLEAR_BACKGROUND
.BLACK_BACKGROUND
.open(fileFromRemote: URL(string: ""),type: .VTT) type -> Required* .VTT
.SRT

Author

Swagat Nayak

License

SNAVPlayerSubtitles is available under the MIT license. See the LICENSE file for more info.

Samples