diff --git a/Example/Podfile b/Example/Podfile index 0b7ac2a..c520f39 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -4,10 +4,10 @@ platform :ios, '10.0' target 'SNAVPlayerSubtitles_Example' do pod 'SNAVPlayerSubtitles', :path => '../' + end target 'SNAVPlayerSubtitles_Tests' do inherit! :search_paths - - end -end + end + diff --git a/Example/Podfile.lock b/Example/Podfile.lock index af3402e..2a89781 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - SNAVPlayerSubtitles (0.1.0) + - SNAVPlayerSubtitles (1.0.2) DEPENDENCIES: - SNAVPlayerSubtitles (from `../`) @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - SNAVPlayerSubtitles: b932f25e15a83428c2d2692851140236b4b7291b + SNAVPlayerSubtitles: a4d8490a4b7423bc538e1cec1e1500de36dd3d84 -PODFILE CHECKSUM: 83b41f54523adb3cb308952467eae8b22b03b2f8 +PODFILE CHECKSUM: 641e43f6db03945ee11d062de304b59fb321b034 COCOAPODS: 1.10.1 diff --git a/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj b/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj index 96ba01a..dfc3b8c 100644 --- a/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj +++ b/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; }; + 8D2885C025FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D2885BF25FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard */; }; 8DEAB51425FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DEAB51325FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift */; }; 8DEAB51925FE2AD100180BB5 /* SNAVPlayerSubtitles.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DEAB51825FE2AD100180BB5 /* SNAVPlayerSubtitles.framework */; }; D0973A5FAF400814CF01B381 /* Pods_SNAVPlayerSubtitles_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89C61F1B62870A75B67442AF /* Pods_SNAVPlayerSubtitles_Example.framework */; }; @@ -45,6 +46,7 @@ 607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; 7BF3B57B2249FAA666612248 /* Pods_SNAVPlayerSubtitles_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SNAVPlayerSubtitles_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 89C61F1B62870A75B67442AF /* Pods_SNAVPlayerSubtitles_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SNAVPlayerSubtitles_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8D2885BF25FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SubtitleWithAVPlayerViewController.storyboard; sourceTree = ""; }; 8DEAB51325FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleWithAVPlayerViewController.swift; sourceTree = ""; }; 8DEAB51825FE2AD100180BB5 /* SNAVPlayerSubtitles.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SNAVPlayerSubtitles.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B70E28048810029E570FFB53 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; @@ -174,6 +176,7 @@ children = ( 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 607FACD91AFB9204008FA782 /* Main.storyboard */, + 8D2885BF25FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard */, ); name = View; sourceTree = ""; @@ -287,6 +290,7 @@ 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, + 8D2885C025FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -532,6 +536,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -547,6 +552,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/Example/SNAVPlayerSubtitles/Info.plist b/Example/SNAVPlayerSubtitles/Info.plist index b3e2967..57d0faf 100644 --- a/Example/SNAVPlayerSubtitles/Info.plist +++ b/Example/SNAVPlayerSubtitles/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard new file mode 100644 index 0000000..ce0f355 --- /dev/null +++ b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.swift b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.swift index 9712153..f88a7d7 100644 --- a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.swift +++ b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.swift @@ -2,7 +2,7 @@ // SubtitleWithAVPlayerViewController.swift // SNAVPlayerSubtitles_Example // -// Created by SWAGAT-CDI on 14/03/21. +// Created by SWAGAT NAYAK on 14/03/21. // Copyright © 2021 CocoaPods. All rights reserved. // @@ -14,29 +14,97 @@ import SNAVPlayerSubtitles class SubtitleWithAVPlayerViewController: UIViewController, AVPlayerViewControllerDelegate { + // MARK: - IB Outlets + // --------------------------------------- + @IBOutlet weak var playUsingDefaultUrlBTN: UIButton!{ + didSet{ + self.playUsingDefaultUrlBTN.layer.cornerRadius = 12 + } + } + + @IBOutlet weak var playUsingInputUrlBTN: UIButton!{ + didSet{ + self.playUsingInputUrlBTN.layer.cornerRadius = 12 + } + } + @IBOutlet weak var subtitleInputField: UITextField! + + + // MARK: - Local variables + // --------------------------------------- var playerViewController: AVPlayerViewController? + + // MARK: - Helper Methods + // --------------------------------------- override func viewDidLoad() { super.viewDidLoad() + + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(true) + // Do any additional setup after loading the view. + + } + + + // MARK: - IB Actions + // --------------------------------------- + @IBAction func onBackBtnPressed(_ sender: UIButton) { + + self.dismiss(animated: true, completion: nil) + } + + @IBAction func playUsingDefaultUrlBTNPressed(_ sender: UIButton) { + + // MARK: - Enter media url here here guard let url = URL(string: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8") else { return } - + let player = AVPlayer(url: url) self.playerViewController = AVPlayerViewController() self.playerViewController?.player = player - self.playerViewController?.allowsPictureInPicturePlayback = true self.playerViewController?.delegate = self self.playerViewController?.player?.play() - - + // MARK: - Enter subtitle url here here (srt or vtt) + self.playerViewController?.addSubtitles().open(fileFromRemote: URL(string: "https://gist.githubusercontent.com/samdutton/ca37f3adaf4e23679957b8083e061177/raw/e19399fbccbc069a2af4266e5120ae6bad62699a/sample.vtt")!) self.present(playerViewController!, animated: true, completion: nil) + } + @IBAction func playUsingInputUrlBTNPressed(_ sender: UIButton) { + + if self.subtitleInputField.text == "" { + showToast(message: "URL Required") + } + } + + + func showToast(message : String) { + + + let toastLabel = UILabel(frame: CGRect(x: 10, y: self.view.frame.size.height-100, width: UIScreen.main.bounds.width-20, height: 40)) + toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.8) + toastLabel.textColor = UIColor.white + toastLabel.textAlignment = .center; + toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0) + toastLabel.text = message + toastLabel.alpha = 1.0 + toastLabel.layer.cornerRadius = 5; + toastLabel.clipsToBounds = true + self.view.addSubview(toastLabel) + UIView.animate(withDuration: 2, delay: 2, options: .curveEaseOut, animations: { + toastLabel.alpha = 0.0 + }, completion: {(isCompleted) in + toastLabel.removeFromSuperview() + }) + } } diff --git a/Example/SNAVPlayerSubtitles/ViewController.swift b/Example/SNAVPlayerSubtitles/ViewController.swift index 2e09b05..e8ca31b 100644 --- a/Example/SNAVPlayerSubtitles/ViewController.swift +++ b/Example/SNAVPlayerSubtitles/ViewController.swift @@ -30,6 +30,9 @@ class ViewController: UIViewController { // --------------------------------------- override func viewDidLoad() { super.viewDidLoad() + + + // Do any additional setup after loading the view, typically from a nib. } @@ -46,6 +49,11 @@ class ViewController: UIViewController { // MARK: - IB Actions // --------------------------------------- @IBAction func onPlayWithAvplayerViewControllerPressed(_ sender: UIButton) { + + let storyBoard : UIStoryboard = UIStoryboard(name: "SubtitleWithAVPlayerViewController", bundle:nil) + let nextViewController = storyBoard.instantiateViewController(withIdentifier: "SubtitleWithAVPlayerViewControllerScreen") as! SubtitleWithAVPlayerViewController + nextViewController.modalPresentationStyle = .fullScreen + self.present(nextViewController, animated:true, completion:nil) } @IBAction func onPlayWithAvplayerPressed(_ sender: UIButton) { diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index d51dc31..730831a 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -1,5 +1,4 @@ import XCTest -import SNAVPlayerSubtitles class Tests: XCTestCase { diff --git a/SNAVPlayerSubtitles/Classes/Aaa.swift b/SNAVPlayerSubtitles/Classes/Aaa.swift deleted file mode 100644 index f84bfe6..0000000 --- a/SNAVPlayerSubtitles/Classes/Aaa.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// Aaa.swift -// Pods-SNAVPlayerSubtitles_Example -// -// Created by SWAGAT-CDI on 14/03/21. -// - -import Foundation -import AVKit - -extension AVPlayerViewController { - - public func getadad() { - - } -} diff --git a/SNAVPlayerSubtitles/Classes/SNAVPlayerSubtitles.swift b/SNAVPlayerSubtitles/Classes/SNAVPlayerSubtitles.swift index be31aec..2d334bc 100644 --- a/SNAVPlayerSubtitles/Classes/SNAVPlayerSubtitles.swift +++ b/SNAVPlayerSubtitles/Classes/SNAVPlayerSubtitles.swift @@ -2,7 +2,7 @@ // SNAVPlayerSubtitles.swift // Pods-SNAVPlayerSubtitles_Example // -// Created by SWAGAT-CDI on 14/03/21. +// Created by SWAGAT NAYAK on 14/03/21. // import ObjectiveC import MediaPlayer