Skip to content

Commit 32fc017

Browse files
committed
Adjustments
Initializer API adjustments Place extension methods into dedicated directories Polish inline API documentation
1 parent 6cae8ed commit 32fc017

File tree

6 files changed

+96
-76
lines changed

6 files changed

+96
-76
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// MuxUpload+AVFoundation.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
extension MuxUpload {
9+
10+
/// Initializes a MuxUpload from an ``AVAsset``
11+
///
12+
/// - Parameters:
13+
/// - uploadURL: the URL of the direct upload that's
14+
/// included in the create a new direct upload URL
15+
/// [response](https://docs.mux.com/api-reference#video/operation/create-direct-upload)
16+
/// - inputAsset: the asset containing audiovisual
17+
/// media to be used as the input for the direct
18+
/// upload
19+
/// - options: options used to control the direct
20+
/// upload of the input to Mux
21+
public convenience init(
22+
uploadURL: URL,
23+
inputAsset: AVAsset,
24+
options: UploadOptions
25+
) {
26+
self.init(
27+
input: UploadInput(asset: inputAsset),
28+
options: options,
29+
uploadManager: .shared
30+
)
31+
}
32+
33+
}

Sources/MuxUploadSDK/PublicAPI/MuxUpload+AVFoundation.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import Foundation
1111
public typealias UploadResult = Result<MuxUpload.Success, MuxUpload.UploadError>
1212

1313
///
14-
/// Uploads a video file to a previously-created Mux Video Direct Upload.
14+
/// Uploads a media asset to Mux using a previously-created
15+
/// Direct Upload signed URL.
1516
///
1617
/// This class is part of a full-stack workflow for uploading video files to Mux Video. In order to use this object you must first have
1718
/// created a [Direct Upload](https://docs.mux.com/guides/video/upload-files-directly) on your server backend.
@@ -66,7 +67,7 @@ public final class MuxUpload : Hashable, Equatable {
6667
input.uploadInfo
6768
}
6869

69-
/// Indicates the status of the upload as it goes
70+
/// Indicates the status of the upload input as it goes
7071
/// through its lifecycle
7172
public enum InputStatus {
7273
/// Upload initialized and not yet started
@@ -91,6 +92,8 @@ public final class MuxUpload : Hashable, Equatable {
9192
case uploadFailed(AVAsset, Status, UploadResult)
9293
}
9394

95+
/// Current status of the upload input as it goes through
96+
/// its lifecycle
9497
public var inputStatus: InputStatus {
9598
switch input.status {
9699
case .ready(let sourceAsset):
@@ -183,9 +186,12 @@ public final class MuxUpload : Hashable, Equatable {
183186

184187
}
185188

186-
/// Initializes a MuxUpload with the given configuration
189+
/// Initializes a MuxUpload from a local file URL with
190+
/// the given configuration
187191
/// - Parameters:
188-
/// - uploadURL: the URL of the direct upload
192+
/// - uploadURL: the URL of the direct upload that's
193+
/// included in the create a new direct upload URL
194+
/// [response](https://docs.mux.com/api-reference#video/operation/create-direct-upload)
189195
/// - videoFileURL: the file:// URL of the upload
190196
/// input
191197
/// - chunkSize: the size of chunks when uploading,
@@ -194,7 +200,8 @@ public final class MuxUpload : Hashable, Equatable {
194200
/// a failed chunk upload request
195201
/// - inputStandardization: enable or disable input
196202
/// standardization by the SDK locally
197-
/// - optOutOfEventTracking: opt out of event tracking
203+
/// - eventTracking: options to opt out of event
204+
/// tracking
198205
public convenience init(
199206
uploadURL: URL,
200207
videoFileURL: URL,
@@ -203,40 +210,43 @@ public final class MuxUpload : Hashable, Equatable {
203210
inputStandardization: UploadOptions.InputStandardization = .init(
204211
targetResolution: UploadOptions.InputStandardization.ResolutionPreset.default
205212
),
206-
optOutOfEventTracking: Bool = false
213+
eventTracking: UploadOptions.EventTracking = UploadOptions.EventTracking(optedOut: false)
207214
) {
208-
let uploadSettings = UploadOptions(
209-
inputStandardization: inputStandardization,
210-
transport: UploadOptions.Transport(
211-
chunkSize: chunkSize,
212-
retriesPerChunk: retriesPerChunk
213-
),
214-
eventTracking: UploadOptions.EventTracking(
215-
optedOut: optOutOfEventTracking
216-
)
217-
)
218-
219-
let inputSourceAsset = AVAsset(url: videoFileURL)
220-
221-
let input = UploadInput(status: .ready(inputSourceAsset))
222-
223215
self.init(
224-
input: input,
225-
options: uploadSettings,
216+
input: UploadInput(asset: AVAsset(url: videoFileURL)),
217+
options: UploadOptions(
218+
inputStandardization: inputStandardization,
219+
transport: UploadOptions.Transport(
220+
chunkSize: chunkSize,
221+
retriesPerChunk: retriesPerChunk
222+
),
223+
eventTracking: eventTracking
224+
),
226225
uploadManager: .shared
227226
)
228227
}
229228

229+
/// Initializes a MuxUpload from a local file URL
230+
///
231+
/// - Parameters:
232+
/// - uploadURL: the URL of the direct upload that's
233+
/// included in the create a new direct upload URL
234+
/// [response](https://docs.mux.com/api-reference#video/operation/create-direct-upload)
235+
/// - inputFileURL: the file:// URL of the upload
236+
/// input
237+
/// - options: options used to control the direct
238+
/// upload of the input to Mux
230239
public convenience init(
231240
uploadURL: URL,
232241
inputFileURL: URL,
233242
options: UploadOptions
234243
) {
235-
let inputSourceAsset = AVAsset(url: inputFileURL)
236-
let input = UploadInput(status: .ready(inputSourceAsset))
237-
238244
self.init(
239-
input: input,
245+
input: UploadInput(
246+
asset: AVAsset(
247+
url: inputFileURL
248+
)
249+
),
240250
manage: true,
241251
options: options,
242252
uploadManager: .shared

Sources/MuxUploadSDK/PublicAPI/Options/UploadOptions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public struct UploadOptions {
9292
targetResolution: .default
9393
)
9494

95+
// Kept private to an invalid combination of parameters
96+
// being used for initialization
9597
private init(
9698
isEnabled: Bool,
9799
targetResolution: ResolutionPreset
@@ -100,7 +102,13 @@ public struct UploadOptions {
100102
self.targetResolution = targetResolution
101103
}
102104

105+
/// Used to initialize ``UploadOptions.InputStandardization``
106+
/// with a target resolution
103107
///
108+
/// - Parameters:
109+
/// - targetResolution: if the input resolution
110+
/// exceeds 1080p, it will be set to the preset
111+
/// after undergoing standardization
104112
public init(
105113
targetResolution: ResolutionPreset
106114
) {

Sources/MuxUploadSDK/PublicAPI/PHAsset+MuxUpload.swift renamed to Sources/MuxUploadSDK/PublicAPI/PhotosKit+MuxUpload/PHAsset+MuxUpload.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@ import Photos
77

88
extension PHAsset {
99

10-
/// Asynchronously initializes ``MuxUpload`` from a
11-
/// requesting for an ``AVAsset`` containing the input.
12-
/// A ``MuxUpload`` can only be initialized from a ``PHAsset``
13-
/// whose ``PHAsset.mediaType`` is
14-
/// ``PHAssetMediaType.video``.
10+
/// Convenience method that requests an ``AVAsset``
11+
/// containing audiovisual media associated with the callee
12+
/// ``PHAsset``. If the request succeeds ``MuxUpload``
13+
/// is initialized with the received ``AVAsset``
1514
///
15+
/// A ``MuxUpload`` can only be initialized from a ``PHAsset``
16+
/// whose ``PHAsset.mediaType`` is ``PHAssetMediaType.video``
1617
///
1718
/// - Parameters:
18-
/// - imageManager: Photos image manager
19+
/// - imageManager: an object that facilitates retrieval
20+
/// of asset data associated with the callee
1921
/// - requestOptions: options used when requesting
20-
/// an ``AVAsset`` from the `imageManager`
21-
/// - uploadURL: the direct upload URL
22-
/// - options: the upload settings
23-
/// - completion: receives the initialized MuxUpload
24-
/// when it is ready, receives nil if initialization
25-
/// failed or if the ``PHAsset`` is not a video.
22+
/// an ``AVAsset`` from a ``PHImageManager`
23+
/// - options: options used to control the direct
24+
/// upload of the input to Mux
25+
/// - uploadURL: the URL of the direct upload that's
26+
/// included in the create a new direct upload URL
27+
/// [response](https://docs.mux.com/api-reference#video/operation/create-direct-upload)
28+
/// - completion: called when initialized ``MuxUpload``
29+
/// is ready, receives nil if the asset data request
30+
/// failed or if the ``PHAsset`` callee is not a video
2631
func prepareForDirectUpload(
2732
from imageManager: PHImageManager = .default(),
2833
requestOptions: PHVideoRequestOptions,
29-
uploadURL: URL,
3034
options: UploadOptions,
35+
uploadURL: URL,
3136
completion: @escaping (MuxUpload?) -> ()
3237
) {
3338
if mediaType != .video {

Sources/MuxUploadSDK/PublicAPI/StandardizationResult.swift

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)