Skip to content

Commit 290759d

Browse files
committed
added Mute setting
1 parent fe2567e commit 290759d

File tree

7 files changed

+60
-25
lines changed

7 files changed

+60
-25
lines changed

Sources/swiftui-loop-videoplayer/enum/Setting.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public enum Setting: Equatable, SettingsConvertible{
2222
/// Loop video
2323
case loop
2424

25+
/// Mute video
26+
case mute
27+
2528
/// File name
2629
case name(String)
2730

Sources/swiftui-loop-videoplayer/protocol/player/LoopingPlayerProtocol.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ public protocol LoopingPlayerProtocol: AbstractPlayer, LayerMakerProtocol{
4949
/// Declare a variable to hold the time observer token outside the if statement
5050
var timeObserver: Any? { get set }
5151

52-
/// Initializes a new player view with specified video asset and configurations.
52+
/// Initializes a new player view with a video asset and specified configurations.
5353
///
5454
/// - Parameters:
55-
/// - asset: The `AVURLAsset` used for video playback.
56-
/// - gravity: The `AVLayerVideoGravity` defining how the video content is displayed within the layer bounds.
57-
/// - timePublishing: Optional `CMTime` that specifies a particular time for publishing or triggering an event.
58-
/// - loop: A Boolean value that indicates whether the video should loop when playback reaches the end of the content.
59-
init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop : Bool)
55+
/// - asset: The `AVURLAsset` for video playback.
56+
/// - gravity: The `AVLayerVideoGravity` determining the video's display within the layer bounds.
57+
/// - timePublishing: Optional `CMTime` for publishing or triggering an event at a specific time.
58+
/// - loop: A Boolean indicating if the video should loop at the end of playback.
59+
/// - mute: A Boolean indicating if the audio playback should be muted.
60+
init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop : Bool, mute: Bool)
6061

6162
/// Sets up the necessary observers on the AVPlayerItem and AVQueuePlayer to monitor changes and errors.
6263
///
@@ -83,15 +84,16 @@ internal extension LoopingPlayerProtocol {
8384
asset: AVURLAsset,
8485
gravity: AVLayerVideoGravity,
8586
timePublishing: CMTime?,
86-
loop: Bool
87+
loop: Bool,
88+
mute: Bool
8789
) {
8890

8991
let player = AVQueuePlayer(items: [])
9092
self.player = player
9193

9294
update(asset: asset, loop: loop)
9395

94-
configurePlayer(player, gravity: gravity, timePublishing: timePublishing, loop: loop)
96+
configurePlayer(player, gravity: gravity, timePublishing: timePublishing, loop: loop, mute: mute)
9597

9698
setupObservers(for: player)
9799
}
@@ -106,9 +108,10 @@ internal extension LoopingPlayerProtocol {
106108
_ player: AVQueuePlayer,
107109
gravity: AVLayerVideoGravity,
108110
timePublishing: CMTime?,
109-
loop : Bool
111+
loop : Bool,
112+
mute : Bool
110113
) {
111-
player.isMuted = true
114+
player.isMuted = mute
112115
playerLayer.player = player
113116
playerLayer.videoGravity = gravity
114117
#if canImport(UIKit)

Sources/swiftui-loop-videoplayer/protocol/view/LoopPlayerViewProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public extension LoopPlayerViewProtocol{
9191
asset: AVURLAsset?) -> PlayerView? {
9292

9393
if let asset{
94-
let player = PlayerView(asset: asset, gravity: settings.gravity, timePublishing: settings.timePublishing, loop: settings.loop)
94+
let player = PlayerView(asset: asset, gravity: settings.gravity, timePublishing: settings.timePublishing, loop: settings.loop, mute: settings.mute)
9595
container.addSubview(player)
9696
activateFullScreenConstraints(for: player, in: container)
9797
return player
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Mute.swift
3+
//
4+
//
5+
// Created by Igor Shelopaev on 10.09.24.
6+
//
7+
8+
import Foundation
9+
10+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, *)
11+
public struct Mute: SettingsConvertible{
12+
13+
// MARK: - Life circle
14+
15+
public init() {}
16+
17+
/// Fetch settings
18+
@_spi(Private)
19+
public func asSettings() -> [Setting] {
20+
[.mute]
21+
}
22+
}

Sources/swiftui-loop-videoplayer/utils/VideoSettings.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public struct VideoSettings: Equatable{
2222
/// Loop video
2323
public let loop: Bool
2424

25+
/// Mute video
26+
public let mute: Bool
27+
2528
/// A CMTime value representing the interval at which the player's current time should be published.
2629
/// If set, the player will publish periodic time updates based on this interval.
2730
public let timePublishing: CMTime?
@@ -70,6 +73,8 @@ public struct VideoSettings: Equatable{
7073

7174
loop = settings.contains(.loop)
7275

76+
mute = settings.contains(.mute)
77+
7378
errorWidgetOff = settings.contains(.errorWidgetOff)
7479
}
7580
}

Sources/swiftui-loop-videoplayer/view/player/ios/LoopingPlayerUIView.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,18 @@ class LoopingPlayerUIView: UIView, LoopingPlayerProtocol {
6363
/// The delegate to be notified about errors encountered by the player.
6464
weak var delegate: PlayerDelegateProtocol?
6565

66-
/// Initializes a new player view with specified video asset and configurations.
66+
/// Initializes a new player view with a video asset and specified configurations.
6767
///
6868
/// - Parameters:
69-
/// - asset: The `AVURLAsset` used for video playback.
70-
/// - gravity: The `AVLayerVideoGravity` defining how the video content is displayed within the layer bounds.
71-
/// - timePublishing: Optional `CMTime` that specifies a particular time for publishing or triggering an event.
72-
/// - loop: A Boolean value that indicates whether the video should loop when playback reaches the end of the content.
73-
required init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop: Bool){
69+
/// - asset: The `AVURLAsset` for video playback.
70+
/// - gravity: The `AVLayerVideoGravity` determining the video's display within the layer bounds.
71+
/// - timePublishing: Optional `CMTime` for publishing or triggering an event at a specific time.
72+
/// - loop: A Boolean indicating if the video should loop at the end of playback.
73+
/// - mute: A Boolean indicating if the audio playback should be muted.
74+
required init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop: Bool, mute: Bool){
7475
super.init(frame: .zero)
7576
setupPlayerComponents(
76-
asset: asset, gravity: gravity, timePublishing : timePublishing, loop: loop
77+
asset: asset, gravity: gravity, timePublishing : timePublishing, loop: loop, mute: mute
7778
)
7879
}
7980

Sources/swiftui-loop-videoplayer/view/player/mac/LoopingPlayerNSView.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ class LoopingPlayerNSView: NSView, LoopingPlayerProtocol {
6565
/// The delegate to be notified about errors encountered by the player.
6666
weak var delegate: PlayerDelegateProtocol?
6767

68-
/// Initializes a new player view with specified video asset and configurations.
68+
/// Initializes a new player view with a video asset and specified configurations.
6969
///
7070
/// - Parameters:
71-
/// - asset: The `AVURLAsset` used for video playback.
72-
/// - gravity: The `AVLayerVideoGravity` defining how the video content is displayed within the layer bounds.
73-
/// - timePublishing: Optional `CMTime` that specifies a particular time for publishing or triggering an event.
74-
/// - loop: A Boolean value that indicates whether the video should loop when playback reaches the end of the content.
75-
required init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop : Bool) {
71+
/// - asset: The `AVURLAsset` for video playback.
72+
/// - gravity: The `AVLayerVideoGravity` determining the video's display within the layer bounds.
73+
/// - timePublishing: Optional `CMTime` for publishing or triggering an event at a specific time.
74+
/// - loop: A Boolean indicating if the video should loop at the end of playback.
75+
/// - mute: A Boolean indicating if the audio playback should be muted.
76+
required init(asset: AVURLAsset, gravity: AVLayerVideoGravity, timePublishing: CMTime?, loop : Bool, mute: Bool) {
7677
super.init(frame: .zero)
7778
setupPlayerComponents(
78-
asset: asset, gravity: gravity, timePublishing: timePublishing, loop: loop
79+
asset: asset, gravity: gravity, timePublishing: timePublishing, loop: loop, mute: mute
7980
)
8081
}
8182

0 commit comments

Comments
 (0)