Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated onAdTimeEvent, onMediaTimeEvent #346

Merged
1 commit merged into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions ios/RNJWPlayer/RNJWPlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import GoogleCast
import JWPlayerKit

class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerDelegate, JWDRMContentKeyDataSource {

var parentView:RNJWPlayerView!

func setDelegates() {
Expand Down Expand Up @@ -155,27 +155,27 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
func playerViewControllerDidDismissFullScreen(_ controller:JWPlayerViewController) {
parentView?.onFullScreenExit?([:])
}

func playerViewController(_ controller:JWPlayerViewController, relatedMenuClosedWithMethod method:JWRelatedInteraction) {

}

func playerViewController(_ controller: JWPlayerKit.JWPlayerViewController, relatedMenuOpenedWithItems items: [JWPlayerKit.JWPlayerItem], withMethod method: JWPlayerKit.JWRelatedInteraction) {

}

func playerViewController(_ controller: JWPlayerKit.JWPlayerViewController, relatedItemBeganPlaying item: JWPlayerKit.JWPlayerItem, atIndex index: Int, withMethod method: JWPlayerKit.JWRelatedMethod) {

}

// MARK: Time events

func onAdTimeEvent(time:JWTimeData) {
override func onAdTimeEvent(_ time:JWTimeData) {
super.onAdTimeEvent(time)
parentView?.onAdTime?(["position": time.position, "duration": time.duration])
}

func onMediaTimeEvent(time:JWTimeData) {
override func onMediaTimeEvent(_ time:JWTimeData) {
super.onMediaTimeEvent(time)
parentView?.onTime?(["position": time.position, "duration": time.duration])
}
Expand All @@ -191,7 +191,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
guard let fairplayCertUrlString = parentView?.fairplayCertUrl, let fairplayCertUrl = URL(string: fairplayCertUrlString) else {
return
}

let request = URLRequest(url: fairplayCertUrl)
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
Expand All @@ -201,7 +201,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
}
task.resume()
}

func contentKeyWithSPCData(_ spcData: Data, completionHandler handler: @escaping (Data?, Date?, String?) -> Void) {
if parentView?.processSpcUrl == nil {
return
Expand All @@ -212,21 +212,21 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
ckcRequest.httpMethod = "POST"
ckcRequest.httpBody = spcData
ckcRequest.addValue("application/octet-stream", forHTTPHeaderField: "Content-Type")

URLSession.shared.dataTask(with: ckcRequest as URLRequest) { (data, response, error) in
if let httpResponse = response as? HTTPURLResponse, (error != nil || httpResponse.statusCode != 200) {
NSLog("DRM ckc request error - %@", error.debugDescription)
handler(nil, nil, nil)
return
}

handler(data, nil, "application/octet-stream")
}.resume()
}
}

// MARK: - AV Picture In Picture Delegate

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
// if (keyPath == "playbackLikelyToKeepUp") {
Expand Down Expand Up @@ -287,7 +287,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD

override func jwplayer(_ player:JWPlayer, isPlayingWithReason reason:JWPlayReason) {
super.jwplayer(player, isPlayingWithReason:reason)

parentView?.onPlay?([:])

parentView?.userPaused = false
Expand Down Expand Up @@ -332,7 +332,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD

override func jwplayer(_ player:JWPlayer, didLoadPlaylistItem item:JWPlayerItem, at index:UInt) {
super.jwplayer(player, didLoadPlaylistItem: item, at: index)

// var sourceDict: [String: Any] = [:]
// var file: String?
//
Expand Down Expand Up @@ -393,7 +393,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD

override func jwplayer(_ player:JWPlayer, didLoadPlaylist playlist:[JWPlayerItem]) {
super.jwplayer(player, didLoadPlaylist: playlist)

let playlistArray:NSMutableArray! = NSMutableArray()

for item:JWPlayerItem? in playlist {
Expand Down Expand Up @@ -537,7 +537,7 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
super.castController(controller, connectionSuspendedWithDevice:device)
parentView?.onConnectionTemporarilySuspended?([:])
}

override func castController(_ controller: JWCastController, devicesAvailable devices:[JWCastingDevice]) {
parentView?.availableDevices = devices

Expand Down Expand Up @@ -595,12 +595,12 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
override func jwplayer(_ player:JWPlayer, updatedCaptionList options:[JWMediaSelectionOption]) {
super.jwplayer(player, updatedCaptionList:options)
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { _ in
let orientation = UIDevice.current.orientation
switch orientation {
switch orientation {
case .portrait, .portraitUpsideDown:
if self.parentView?.currentConfig["exitFullScreenOnPortrait"] as? Bool ?? false {
super.dismissFullScreen(animated: true)
Expand All @@ -610,5 +610,5 @@ class RNJWPlayerViewController : JWPlayerViewController, JWPlayerViewControllerD
}
})
}

}