Content-Length: 483319 | pFad | http://github.com/muxinc/mux-player-swift/commit/c812263c23e679567d49063718e2e61c0a80595c

4A feat: support all MuxCore overrides and set default values (#9) · muxinc/mux-player-swift@c812263 · GitHub
Skip to content

Commit

Permalink
feat: support all MuxCore overrides and set default values (#9)
Browse files Browse the repository at this point in the history
* feat: support all MuxCore overrides

* fix: set player software name and version

* feat: support environment key override via MonitoringOptions

* fix: remove binding from bindings dictionary

* build: use v3.3.2 MUXSDKStats, fixes Xcode warning

* fix: pass nil for playback ID inference
  • Loading branch information
andrewjl-mux authored Oct 3, 2023
1 parent 87865e6 commit c812263
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/muxinc/mux-stats-sdk-avplayer",
"state" : {
"revision" : "7b0e6e2eda1298e145264c5c4e8663d0f8e807d3",
"version" : "3.3.1"
"revision" : "5a310713d8330cb2c8e4755d9a80088697536d65",
"version" : "3.3.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/muxinc/mux-stats-sdk-avplayer",
exact: "3.3.1"
exact: "3.3.2"
),
.package(
url: "https://github.com/apple/swift-docc-plugin",
Expand Down
2 changes: 1 addition & 1 deletion Package@swift-5.8.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/muxinc/mux-stats-sdk-avplayer",
exact: "3.3.1"
exact: "3.3.2"
),
.package(
url: "https://github.com/apple/swift-docc-plugin",
Expand Down
59 changes: 48 additions & 11 deletions Sources/MuxAVPlayerSDK/Monitoring/Monitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AVFoundation
import AVKit
import Foundation

import MuxCore
import MUXSDKStats

class Monitor {
Expand All @@ -23,20 +24,54 @@ class Monitor {
playerViewController: AVPlayerViewController,
options: MonitoringOptions
) {
let customerPlayerData = MUXSDKCustomerPlayerData()

let customerData = MUXSDKCustomerData()
customerData.customerPlayerData = customerPlayerData
let monitoredPlayer: MonitoredPlayer

let binding = MUXSDKStats.monitorAVPlayerViewController(
playerViewController,
withPlayerName: options.playerName,
customerData: customerData
)
if let customerData = options.customerData {

let binding = MUXSDKStats.monitorAVPlayerViewController(
playerViewController,
withPlayerName: options.playerName,
customerData: customerData
)

monitoredPlayer = MonitoredPlayer(
name: options.playerName,
binding: binding!
)

} else {

let customerData = MUXSDKCustomerData()

if let environmentKey = options.environmentKey {
let customerPlayerData = MUXSDKCustomerPlayerData()
customerPlayerData.environmentKey = environmentKey
customerData.customerPlayerData = customerPlayerData
}

let monitoredPlayer = MonitoredPlayer(
name: options.playerName,
binding: binding!
let binding = MUXSDKStats.monitorAVPlayerViewController(
playerViewController,
withPlayerName: options.playerName,
customerData: customerData
)

monitoredPlayer = MonitoredPlayer(
name: options.playerName,
binding: binding!
)
}

let playerData = MUXSDKPlayerData()
playerData.playerSoftwareVersion = SemanticVersion.versionString
playerData.playerSoftwareName = "MuxAVPlayerViewController"

let playbackEvent = MUXSDKPlaybackEvent()
playbackEvent.playerData = playerData

MUXSDKCore.dispatchEvent(
playbackEvent,
forPlayer: options.playerName
)

let objectIdentifier = ObjectIdentifier(playerViewController)
Expand All @@ -51,5 +86,7 @@ class Monitor {
guard let playerName = bindings[objectIdentifier]?.name else { return }

MUXSDKStats.destroyPlayer(playerName)

bindings.removeValue(forKey: objectIdentifier)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ extension AVPlayerViewController {
//github.com/ - monitoringOptions: Options to customize monitoring
//github.com/ data reported by Mux
public convenience init(
publicPlaybackID: String,
playbackID: String,
monitoringOptions: MonitoringOptions
) {
self.init()

let playerItem = AVPlayerItem(playbackID: publicPlaybackID)
let playerItem = AVPlayerItem(playbackID: playbackID)

let player = AVPlayer(playerItem: playerItem)

Expand All @@ -63,7 +63,8 @@ extension AVPlayerViewController {
//github.com/ - Parameters:
//github.com/ - playbackID: playback ID of the Mux Asset
//github.com/ you'd like to play
//github.com/ - play
//github.com/ - playbackOptions: playback-related options such
//github.com/ as custom domain and maximum resolution
convenience init(
playbackID: String,
playbackOptions: PlaybackOptions
Expand Down Expand Up @@ -95,8 +96,8 @@ extension AVPlayerViewController {
//github.com/ - Parameters:
//github.com/ - playbackID: playback ID of the Mux Asset
//github.com/ you'd like to play
//github.com/ - customDomain: custom playback domain, custom
//github.com/ domains need to be configured as described [here](https://docs.mux.com/guides/video/use-a-custom-domain-for-streaming#use-your-own-domain-for-delivering-videos-and-images) first
//github.com/ - playbackOptions: playback-related options such
//github.com/ as custom domain and maximum resolution
//github.com/ - monitoringOptions: Options to customize monitoring
//github.com/ data reported by Mux
convenience init(
Expand Down
24 changes: 20 additions & 4 deletions Sources/MuxAVPlayerSDK/PublicAPI/Options/MonitoringOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

import Foundation

import MuxCore

//github.com/ Options to customize monitoring data reported by Mux
public struct MonitoringOptions {

//github.com/ Environment key associated with the monitoring data
public var environmentKey: String
var environmentKey: String?

//github.com/ Identifies the player name
public var playerName: String

var customerData: MUXSDKCustomerData?

//github.com/ Initializes options to customize monitoring by Mux
//github.com/ - Parameter playbackID: helps identify your Data environment,
public init(playbackID: String) {
//github.com/ Mux will use the same environment as the one used
//github.com/ associated with the playback ID
self.environmentKey = playbackID
self.environmentKey = nil
let uniquePlayerName = "\(playbackID)-\(UUID().uuidString)"
self.playerName = uniquePlayerName
}
Expand All @@ -32,4 +34,18 @@ public struct MonitoringOptions {
self.environmentKey = environmentKey
self.playerName = playerName
}

//github.com/ Initializes options to customize monitoring by Mux
//github.com/ using the existing `MUXSDKStats` customer data override.
//github.com/ - Parameters:
//github.com/ - customerData: passed through as-is when initializing
//github.com/ Mux Data monitoring
public init(
customerData: MUXSDKCustomerData,
playerName: String
) {
self.customerData = customerData
self.environmentKey = nil
self.playerName = playerName
}
}
34 changes: 34 additions & 0 deletions Tests/MuxAVPlayerSDKTests/MonitorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// MonitorTests.swift
//

import AVKit
import Foundation
import XCTest

@testable import MuxAVPlayerSDK

class MonitorTests: XCTestCase {

func testMonitoringLifecycle() throws {

let playerViewController = AVPlayerViewController(
playbackID: "abc"
)

let monitor = Monitor.shared

XCTAssertEqual(
monitor.bindings.count,
1
)

playerViewController.stopMonitoring()

XCTAssertTrue(
monitor.bindings.isEmpty
)

}

}

0 comments on commit c812263

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/muxinc/mux-player-swift/commit/c812263c23e679567d49063718e2e61c0a80595c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy