Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff27a93

Browse files
update
1 parent 683f0ad commit ff27a93

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

‎Sources/swiftui-loop-videoplayer/fn/fn+.swift‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,24 @@ func getSeekTime(for time: Double, duration : CMTime) -> CMTime?{
240240

241241
return seekTime
242242
}
243+
244+
/// Creates an `AVPlayerItem` with optional subtitle merging.
245+
/// - Parameters:
246+
/// - asset: The main video asset.
247+
/// - settings: A `VideoSettings` object containing subtitle configuration.
248+
/// - Returns: A new `AVPlayerItem` configured with the merged or original asset.
249+
func createPlayerItem(with settings: VideoSettings) -> AVPlayerItem? {
250+
251+
guard let asset = assetFor(settings) else{
252+
return nil
253+
}
254+
255+
if let subtitleAsset = subtitlesAssetFor(settings),
256+
let mergedAsset = mergeAssetWithSubtitles(videoAsset: asset, subtitleAsset: subtitleAsset) {
257+
// Create and return a new `AVPlayerItem` using the merged asset
258+
return AVPlayerItem(asset: mergedAsset)
259+
} else {
260+
// Create and return a new `AVPlayerItem` using the original asset
261+
return AVPlayerItem(asset: asset)
262+
}
263+
}

‎Sources/swiftui-loop-videoplayer/protocol/player/AbstractPlayer.swift‎

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public protocol AbstractPlayer: AnyObject {
3131
/// The current asset being played, if available.
3232
var currentAsset : AVURLAsset? { get }
3333

34+
/// Check if looping is applied
35+
var isLooping : Bool { get }
36+
3437
/// Adjusts the brightness of the video. Default is 0 (no change), with positive values increasing and negative values decreasing brightness.
3538
var brightness: Float { get set }
3639

@@ -55,6 +58,12 @@ public protocol AbstractPlayer: AnyObject {
5558
/// Pauses the current video playback.
5659
/// This method should be implemented to pause the video, allowing it to be resumed later from the same position.
5760
func pause()
61+
62+
/// Stop and clean player
63+
func stop()
64+
65+
/// Inserts a new player item into the media queue of the player.
66+
func insert(_ item : AVPlayerItem)
5867

5968
/// Seeks the video to a specific time.
6069
/// This method moves the playback position to the specified time with precise accuracy.
@@ -81,7 +90,19 @@ public protocol AbstractPlayer: AnyObject {
8190
/// - Parameter volume: A `Float` value between 0.0 (mute) and 1.0 (full volume).
8291
/// If the value is out of range, it will be clamped to the nearest valid value.
8392
func setVolume(_ volume: Float)
84-
93+
94+
/// Sets the playback speed for the video playback.
95+
func setPlaybackSpeed(_ speed: Float)
96+
97+
/// Sets the subtitles for the video playback to a specified language or turns them off.
98+
func setSubtitles(to language: String?)
99+
100+
/// Enables looping for the current video item.
101+
func loop()
102+
103+
/// Disables looping for the current video item.
104+
func unloop()
105+
85106
/// Adjusts the brightness of the video playback.
86107
/// - Parameter brightness: A `Float` value representing the brightness level. Typically ranges from -1.0 to 1.0.
87108
func adjustBrightness(to brightness: Float)
@@ -103,9 +124,6 @@ public protocol AbstractPlayer: AnyObject {
103124
/// Sets the playback command for the video player.
104125
func setCommand(_ value: PlaybackCommand)
105126

106-
/// Applies the current set of filters to the video using an AVVideoComposition.
107-
func applyVideoComposition()
108-
109127
/// Updates the current playback asset, settings, and initializes playback or a specific action when the asset is ready.
110128
func update(settings: VideoSettings)
111129
}
@@ -164,7 +182,7 @@ extension AbstractPlayer{
164182
pause()
165183

166184
if !isEmptyQueue() { // Cleaning
167-
if isLooping(){
185+
if isLooping{
168186
unloop()
169187
}
170188

@@ -177,28 +195,6 @@ extension AbstractPlayer{
177195
func insert(_ item : AVPlayerItem){
178196
player?.insert(item, after: nil)
179197
}
180-
181-
/// Creates an `AVPlayerItem` with optional subtitle merging.
182-
/// - Parameters:
183-
/// - asset: The main video asset.
184-
/// - settings: A `VideoSettings` object containing subtitle configuration.
185-
/// - Returns: A new `AVPlayerItem` configured with the merged or original asset.
186-
func createPlayerItem(with settings: VideoSettings) -> AVPlayerItem? {
187-
188-
guard let asset = assetFor(settings) else{
189-
delegate?.didReceiveError(.sourceNotFound(settings.name))
190-
return nil
191-
}
192-
193-
if let subtitleAsset = subtitlesAssetFor(settings),
194-
let mergedAsset = mergeAssetWithSubtitles(videoAsset: asset, subtitleAsset: subtitleAsset) {
195-
// Create and return a new `AVPlayerItem` using the merged asset
196-
return AVPlayerItem(asset: mergedAsset)
197-
} else {
198-
// Create and return a new `AVPlayerItem` using the original asset
199-
return AVPlayerItem(asset: asset)
200-
}
201-
}
202198

203199
/// Seeks the video to a specific time in the timeline.
204200
/// This method adjusts the playback position to the specified time with precise accuracy.
@@ -308,7 +304,7 @@ extension AbstractPlayer{
308304
}
309305

310306
/// Check if looping is applied
311-
func isLooping()-> Bool{
307+
var isLooping: Bool{
312308
playerLooper != nil
313309
}
314310

@@ -320,7 +316,7 @@ extension AbstractPlayer{
320316
}
321317

322318
// Check if the video is already being looped
323-
if isLooping() {
319+
if isLooping {
324320
return
325321
}
326322

@@ -331,7 +327,7 @@ extension AbstractPlayer{
331327
/// This method removes the `playerLooper`, stopping the loop.
332328
func unloop() {
333329
// Check if the video is not looped (i.e., playerLooper is nil)
334-
guard isLooping() else {
330+
guard isLooping else {
335331
return // Not looped, no need to unloop
336332
}
337333

@@ -373,7 +369,6 @@ extension AbstractPlayer{
373369
filters.append(value)
374370
}
375371

376-
377372
/// Removes all applied CIFilters from the video playback.
378373
///
379374
/// This function clears the array of filters and optionally re-applies the video composition
@@ -397,7 +392,7 @@ extension AbstractPlayer{
397392
/// This method combines the existing filters and brightness/contrast adjustments, creates a new video composition,
398393
/// and assigns it to the current AVPlayerItem. The video is paused during this process to ensure smooth application.
399394
/// This method is not supported on Vision OS.
400-
func applyVideoComposition() {
395+
privatefunc applyVideoComposition() {
401396
guard let player = player else { return }
402397
let allFilters = combineFilters(filters, brightness, contrast)
403398

‎Sources/swiftui-loop-videoplayer/protocol/player/ExtPlayerProtocol.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ internal extension ExtPlayerProtocol {
181181
currentSettings = settings
182182

183183
guard let newItem = createPlayerItem(with: settings) else{
184+
delegate?.didReceiveError(.sourceNotFound(settings.name))
184185
return
185186
}
186187

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /