Skip to content

Commit

Permalink
NA
Browse files Browse the repository at this point in the history
  • Loading branch information
swagatnayak committed Mar 15, 2021
1 parent de947ee commit 6378874
Show file tree
Hide file tree
Showing 10 changed files with 748 additions and 44 deletions.
18 changes: 18 additions & 0 deletions Example/SNAVPlayerSubtitles.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
8D2885D325FEAD4300478180 /* SubtitleWithAVPlayer.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SubtitleWithAVPlayer.storyboard; sourceTree = "<group>"; };
8D2885D725FEAD7C00478180 /* SubtitleWithAVPlayerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleWithAVPlayerController.swift; sourceTree = "<group>"; };
8D2885E325FEB54E00478180 /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = "<group>"; };
8DEAB51325FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleWithAVPlayerViewController.swift; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -177,6 +183,7 @@
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
8D2885BF25FE5DD300478180 /* SubtitleWithAVPlayerViewController.storyboard */,
8D2885D325FEAD4300478180 /* SubtitleWithAVPlayer.storyboard */,
);
name = View;
sourceTree = "<group>";
Expand All @@ -186,6 +193,8 @@
children = (
8DEAB51325FE224500180BB5 /* SubtitleWithAVPlayerViewController.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
8D2885D725FEAD7C00478180 /* SubtitleWithAVPlayerController.swift */,
8D2885E325FEB54E00478180 /* Player.swift */,
);
name = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)",
Expand All @@ -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)",
Expand Down
104 changes: 104 additions & 0 deletions Example/SNAVPlayerSubtitles/Player.swift
Original file line number Diff line number Diff line change
@@ -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
}

}
Loading

0 comments on commit 6378874

Please sign in to comment.