Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions Sources/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public enum PlayerError: Int {

var bufferedTime: TimeInterval { get }

var isMuted: Bool { get set }

var isSeekInProgress: Bool { get }

var playing: Bool { get }

var ended: Bool { get }
Expand All @@ -76,6 +80,9 @@ public enum PlayerError: Int {
/// Play the video
func play()

/// Set Rate of video
func setRate(_ rate: Float)

/// Pause the video
func pause()
}
Expand Down Expand Up @@ -107,6 +114,7 @@ public enum PlayerError: Int {
@objc public enum FillMode: Int {
case fit
case fill
case scaleToFit
}

/// The metadata that should be attached to any type of text track.
Expand Down
16 changes: 15 additions & 1 deletion Sources/RegularPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension AVMediaSelectionOption: TextTrackMetadata {

/// A RegularPlayer is used to play regular videos.
@objc open class RegularPlayer: NSObject, Player, ProvidesView {

public struct Constants {
public static let TimeUpdateInterval: TimeInterval = 0.1
}
Expand All @@ -35,7 +36,7 @@ extension AVMediaSelectionOption: TextTrackMetadata {
private var seekTolerance: CMTime?

private var seekTarget: CMTime = CMTime.invalid
private var isSeekInProgress: Bool = false
public var isSeekInProgress: Bool = false

// MARK: - Public API

Expand Down Expand Up @@ -115,6 +116,12 @@ extension AVMediaSelectionOption: TextTrackMetadata {
}
}

public var isMuted: Bool = true {
didSet {
player.isMuted = isMuted
}
}

public var playing: Bool {
return self.player.rate > 0
}
Expand All @@ -136,6 +143,10 @@ extension AVMediaSelectionOption: TextTrackMetadata {
self.player.play()
}

open func setRate(_ rate: Float) {
self.player.rate = rate
}

open func pause() {
self.player.pause()
}
Expand Down Expand Up @@ -424,6 +435,9 @@ extension RegularPlayer: FillModeCapable {
case .fill:

gravity = .resizeAspectFill
case .scaleToFit:

gravity = .resize
}

(self.view.layer as! AVPlayerLayer).videoGravity = gravity
Expand Down