Skip to content

Commit

Permalink
Add a resource loader mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Oct 30, 2018
1 parent 1bb7b84 commit 6e47513
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Sodes/SodesAudio/PlaybackController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ fileprivate enum PlaybackMode: String {
case fromFileUrl
}

public enum ResourceLoaderMode: String {
case automaticDetection
case system
case sodes
}

/// Manages playback of audio from a remote or local audio file.
public class PlaybackController: NSObject {

Expand Down Expand Up @@ -231,11 +237,14 @@ public class PlaybackController: NSObject {

/// The current playback mode.
fileprivate var playbackMode: PlaybackMode = .fromRemoteUrl

/// The current resource loader mode.
public fileprivate(set) var resourceLoaderMode: ResourceLoaderMode = .automaticDetection

// MARK: Init/Deinit

/// Designated initializer.
public init(resourcesDirectory: URL, defaults: UserDefaults, customLoadingScheme: String = "playbackcontroller") {
public init(resourcesDirectory: URL, defaults: UserDefaults, customLoadingScheme: String = "playbackcontroller", resourceLoaderMode: ResourceLoaderMode = .automaticDetection) {
player = AVPlayer()

// Discussion (DTS 696294259, rdar://42881405)
Expand All @@ -245,6 +254,7 @@ public class PlaybackController: NSObject {
// and (as a side-effect) allows the pure audio playback.
player.allowsExternalPlayback = false

self.resourceLoaderMode = resourceLoaderMode
self.resourceLoaderDelegate = ResourceLoaderDelegate(
customLoadingScheme: customLoadingScheme,
resourcesDirectory: resourcesDirectory,
Expand Down Expand Up @@ -343,7 +353,8 @@ public class PlaybackController: NSObject {
}
asset = AVURLAsset(url: fileUrl)
playbackMode = .fromFileUrl
} else if let delegatedAsset = resourceLoaderDelegate.prepareAsset(for: source.remoteUrl) {
}
else if let delegatedAsset = resourceLoaderDelegate.prepareAsset(for: source.remoteUrl), resourceLoaderMode == .automaticDetection || resourceLoaderMode == .sodes {
// Enable automatic waiting when streaming over the network.
if #available(iOS 10.0, *) {
// BUG in iOS 9 and 10: it occurs while seeking a specific position of the current source using a streaming
Expand All @@ -356,7 +367,8 @@ public class PlaybackController: NSObject {
}
asset = delegatedAsset
playbackMode = .fromResourceLoader
} else {
}
else {
// Enable automatic waiting when streaming over the network.
if #available(iOS 10.0, *) {
player.automaticallyWaitsToMinimizeStalling = true
Expand Down

0 comments on commit 6e47513

Please sign in to comment.