diff --git a/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj b/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj index dfc3b8c..f7c325b 100644 --- a/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj +++ b/Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj @@ -15,6 +15,9 @@ 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 */; }; + 8D2885D425FEAD4300478180 /* SubtitleWithAVPlayer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D2885D325FEAD4300478180 /* SubtitleWithAVPlayer.storyboard */; }; + 8D2885D825FEAD7C00478180 /* SubtitleWithAVPlayerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D2885D725FEAD7C00478180 /* SubtitleWithAVPlayerController.swift */; }; + 8D2885E425FEB54E00478180 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D2885E325FEB54E00478180 /* Player.swift */; }; 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 */; }; @@ -47,6 +50,9 @@ 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 = ""; }; + 8D2885D325FEAD4300478180 /* SubtitleWithAVPlayer.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SubtitleWithAVPlayer.storyboard; sourceTree = ""; }; + 8D2885D725FEAD7C00478180 /* SubtitleWithAVPlayerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleWithAVPlayerController.swift; sourceTree = ""; }; + 8D2885E325FEB54E00478180 /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; 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 = ""; }; @@ -177,6 +183,7 @@ 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 607FACD91AFB9204008FA782 /* Main.storyboard */, 8D2885BF25FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard */, + 8D2885D325FEAD4300478180 /* SubtitleWithAVPlayer.storyboard */, ); name = View; sourceTree = ""; @@ -186,6 +193,8 @@ children = ( 8DEAB51325FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift */, 607FACD71AFB9204008FA782 /* ViewController.swift */, + 8D2885D725FEAD7C00478180 /* SubtitleWithAVPlayerController.swift */, + 8D2885E325FEB54E00478180 /* Player.swift */, ); name = Controller; sourceTree = ""; @@ -254,10 +263,12 @@ TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = RNPJ777A4C; LastSwiftMigration = 1240; }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + DevelopmentTeam = RNPJ777A4C; LastSwiftMigration = 1240; TestTargetID = 607FACCF1AFB9204008FA782; }; @@ -287,6 +298,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8D2885D425FEAD4300478180 /* SubtitleWithAVPlayer.storyboard in Resources */, 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, @@ -376,6 +388,8 @@ 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 8DEAB51425FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift in Sources */, 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, + 8D2885E425FEB54E00478180 /* Player.swift in Sources */, + 8D2885D825FEAD7C00478180 /* SubtitleWithAVPlayerController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -529,6 +543,7 @@ baseConfigurationReference = 0E7D9A0471BF75E335CC7D0A /* Pods-SNAVPlayerSubtitles_Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = RNPJ777A4C; INFOPLIST_FILE = SNAVPlayerSubtitles/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; @@ -545,6 +560,7 @@ baseConfigurationReference = BF3CC3937DAE20E0C09729ED /* Pods-SNAVPlayerSubtitles_Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = RNPJ777A4C; INFOPLIST_FILE = SNAVPlayerSubtitles/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; @@ -560,6 +576,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 6057CC170CE7D09FF225E1B5 /* Pods-SNAVPlayerSubtitles_Tests.debug.xcconfig */; buildSettings = { + DEVELOPMENT_TEAM = RNPJ777A4C; FRAMEWORK_SEARCH_PATHS = ( "$(PLATFORM_DIR)/Developer/Library/Frameworks", "$(inherited)", @@ -582,6 +599,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 2D1F351AC894B49543BDF4F8 /* Pods-SNAVPlayerSubtitles_Tests.release.xcconfig */; buildSettings = { + DEVELOPMENT_TEAM = RNPJ777A4C; FRAMEWORK_SEARCH_PATHS = ( "$(PLATFORM_DIR)/Developer/Library/Frameworks", "$(inherited)", diff --git a/Example/SNAVPlayerSubtitles/Player.swift b/Example/SNAVPlayerSubtitles/Player.swift new file mode 100644 index 0000000..d393003 --- /dev/null +++ b/Example/SNAVPlayerSubtitles/Player.swift @@ -0,0 +1,104 @@ +// +// Player.swift +// SNAVPlayerSubtitles_Example +// +// Created by SWAGAT-CDI on 15/03/21. +// Copyright © 2021 CocoaPods. All rights reserved. +// + +import UIKit +import AVKit + +class Player: UIViewController { + + // MARK: - IB Outlets + // --------------------------------------- + @IBOutlet weak var playerView: UIView! + @IBOutlet weak var subtitleBTN: UIButton!{ + didSet{ + self.subtitleBTN.layer.cornerRadius = 8 + } + } + + + // MARK: - Local Variables + // --------------------------------------- + private var playerLayer: AVPlayerLayer? + private var player: AVPlayer? + private var isSubtitleShow: Bool = true{ + + didSet{ + + if self.isSubtitleShow { + self.subtitleBTN.setTitle("Hide Subtitle", for: .normal) + + }else{ + self.subtitleBTN.setTitle("Show Subtitle", for: .normal) + + } + + } + } + + + // MARK: - Helper methods + // --------------------------------------- + override func viewDidLoad() { + super.viewDidLoad() + + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(true) + + + guard let url = URL(string: "http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8") else { + return + } + + let asset = AVURLAsset(url: url) + let item = AVPlayerItem(asset: asset) + player = AVPlayer(playerItem: item) + self.playerLayer = AVPlayerLayer(player: player) + + if let playerLayer = self.playerLayer { + + self.playerView.layer.insertSublayer(playerLayer, at: 0) + playerLayer.frame = self.playerView.bounds + playerLayer.videoGravity = .resizeAspect + + + } + self.player?.addSubtitles(view: self.playerView).open(fileFromRemote: URL(string: "https://raw.githubusercontent.com/swagatnayak/SNAVPlayerSubtitles/master/SNAVPlayerSubtitlesSample")!) + + player?.play() + + } + + + + //MARK: - IB Actions + @IBAction func onBackPressed(_ sender: UIButton) { + + self.dismiss(animated: true, completion: nil) + } + @IBAction func onCaptionBtnClicked(_ sender: UIButton) { + + + if !self.isSubtitleShow { + + // MARK: - To show subtitle again you need to call open() again + self.player?.addSubtitles(view: self.playerView).open(fileFromRemote: URL(string: "https://raw.githubusercontent.com/swagatnayak/SNAVPlayerSubtitles/master/SNAVPlayerSubtitlesSample")!) + }else{ + + //MARK - Hide subtitle + self.player?.hideSubtitle() + + } + + + + self.isSubtitleShow = !self.isSubtitleShow + } + +} diff --git a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayer.storyboard b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayer.storyboard new file mode 100644 index 0000000..925b2df --- /dev/null +++ b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayer.storyboard @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerController.swift b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerController.swift new file mode 100644 index 0000000..47bc98e --- /dev/null +++ b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerController.swift @@ -0,0 +1,38 @@ +// +// SubtitleWithAVPlayerController.swift +// SNAVPlayerSubtitles_Example +// +// Created by SWAGAT-CDI on 15/03/21. +// Copyright © 2021 CocoaPods. All rights reserved. +// + +import UIKit + +class SubtitleWithAVPlayerController: UIViewController { + + @IBOutlet weak var playWithDefaultUrlBTNAVPlayer: UIButton!{ + didSet{ + self.playWithDefaultUrlBTNAVPlayer.layer.cornerRadius = 12 + } + } + @IBOutlet weak var playWithUrlBTNAVPlayer: UIButton!{ + didSet{ + self.playWithUrlBTNAVPlayer.layer.cornerRadius = 12 + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + + @IBAction func backBTNPressed(_ sender: UIButton) { + self.dismiss(animated: true, completion: nil) + } + @IBAction func onPlayUsingDefaultUrlPressed(_ sender: UIButton) { + + self.performSegue(withIdentifier: "goToPlayer", sender: nil) + } +} diff --git a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard index ce0f355..d517900 100644 --- a/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard +++ b/Example/SNAVPlayerSubtitles/SubtitleWithAVPlayerViewController.storyboard @@ -72,15 +72,18 @@ - +