diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..4cae29e --- /dev/null +++ b/Package.swift @@ -0,0 +1,21 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. +import PackageDescription + +let package = Package( + name: "WSAudioKit", + platforms: [ + .iOS(.v11) + ], + products: [ + .library( + name: "WSAudioKit", + targets: ["WSAudioKit"]) + ], + targets: [ + .target( + name: "WSAudioKit", + path: ".", + sources: ["Source"]) + ] +) diff --git a/README.md b/README.md index eeef7d4..718f8cd 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,55 @@ -# Sodes Audio Whitesmith version +# WSAudioKit -We turned this into a library and it's possible to use it with Carthage: +### Convenient wrapper around AVFoundation & MediaPlayer. + +## Installation + +#### CocoaPod: + +``` +pod 'WSAudioKit' +``` + +#### Carthage: ``` github "whitesmith/WSAudioKit" ``` -## sodes-audio-example +## Usage + +``` +let controller = PlaybackController( + resourcesDirectory: AudioManager.defaultDirectory, + defaults: UserDefaults.standard, + resourceLoaderMode: .system +) +controller.artworkProvider = AudioManager.artworkFetcher +controller.backwardSkipInterval = 30 +controller.forwardSkipInterval = 30 + +NotificationCenter.default.addObserver(self, selector: #selector(self.updateUI), name: UIApplication.willEnterForegroundNotification, object: nil) + +NotificationCenter.default.addObserver(self, selector: #selector(self.savePosition), name: UIApplication.didEnterBackgroundNotification, object: nil) + +playbackControllerNotificationvDidUpdateElapsedTimeToken = center.addObserver(forName: PlaybackControllerNotification.DidUpdateElapsedTime.name, object: nil, queue: .main) { +... +} + +playbackControllerNotificationDidUpdateStatusToken = center.addObserver(forName: PlaybackControllerNotification.DidUpdateStatus.name, object: nil, queue: .main) { [weak self] +... +} + +playbackControllerNotificationDidPlayToEndToken = center.addObserver(forName: PlaybackControllerNotification.DidPlayToEnd.name, object: nil, queue: .main) { [weak self] (note) in +... +} +``` + +## Acknowledgements + +This is a modified copy of [sodes-audio](https://github.com/jaredsinclair/sodes-audio-example), a convenient wrapper around CommonCrypto that can be used in a Swift framework. + +### Sodes-audio-example An example AVAssetResourceLoaderDelegate implementation. A variation of this will be used in **’sodes**, a podcast app I'm working on. @@ -14,20 +57,13 @@ This repo accompanies a blog post [which can be found here](http://blog.jaredsin You are welcome to use this code as allowed under the generous terms of the MIT License, but **this code is not intended to be used as a re-usable library**. It's highly optimized for the needs of my particular app. I'm sharing it here for the benefit of anyone who's looking for an example of how to write an AVAssetResourceLoaderDelegate implementation. -## What It Does +### What It Does Contains an example implementation of an AVAssetResourceLoaderDelegate which downloads the requested byte ranges to a "scratch file" of locally-cached byte ranges. It also re-uses previously-downloaded byte ranges from that scratch file to service future requests that overlap the downloaded byte ranges, both during the current app session and in future sessions. This helps limit the number of times the same bytes are downloaded when streaming a podcast episode over more than one app session. Ideally each byte should never be downloaded more than once. When a request for a byte range is sent to the resource loader delegate, an array of "subrequests" is formed which are either scratch file requests or network requests. Scratch file requests read the data from existing byte ranges in the scratch file which have already been downloaded. Network requests are made for any gaps in the scratch file. The results of network requests are both passed to the AVAssetResourceLoader and written to the scratch file to be re-used later if the need arises. -## TL;DR Files - -- [ResourceLoaderDelegate.swift](https://github.com/jaredsinclair/sodes-audio-example/blob/master/Sodes/SodesAudio/ResourceLoaderDelegate.swift) -- [DataRequestLoader.swift](https://github.com/jaredsinclair/sodes-audio-example/blob/master/Sodes/SodesAudio/DataRequestLoader.swift) -- [ResourceLoaderSubrequest.swift](https://github.com/jaredsinclair/sodes-audio-example/blob/master/Sodes/SodesAudio/ResourceLoaderSubrequest.swift) -- [PlaybackController.swift](https://github.com/jaredsinclair/sodes-audio-example/blob/master/Sodes/SodesAudio/PlaybackController.swift) - -## Sample App Screenshot +### Sample App Screenshot This repository also contains an example application so you can see it in action. @@ -37,6 +73,3 @@ Delete and reinstall the app to clear out the scratch file (or change the hard-c -## Acknowledgements - -Contains a modified copy of [CommonCryptoSwift](https://github.com/onmyway133/Arcane), a convenient wrapper around CommonCrypto that can be used in a Swift framework. diff --git a/Source/Info.plist b/Source/Info.plist index d3de8ee..ca23c84 100755 --- a/Source/Info.plist +++ b/Source/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion diff --git a/WSAudioKit.podspec b/WSAudioKit.podspec new file mode 100644 index 0000000..433a014 --- /dev/null +++ b/WSAudioKit.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = "WSAudioKit" + s.version = "1.0.0" + s.summary = "Convenient wrapper around AVFoundation & MediaPlayer" + s.homepage = "https://github.com/whitesmith/WSAudioKit" + s.license = 'MIT' + s.author = { "Ricardo Pereira" => "ricardopereira@whitesmith.co" } + s.source = { :git => "https://github.com/whitesmith/WSAudioKit.git", :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/whitesmithco' + s.platform = :ios, '11.0' + s.requires_arc = true + s.swift_version = '5.3' + s.source_files = 'Source/**/*.{h,swift}' + s.frameworks = 'UIKit' +end diff --git a/WSAudioKit.xcodeproj/project.pbxproj b/WSAudioKit.xcodeproj/project.pbxproj index 2cd42ae..e9c0b81 100644 --- a/WSAudioKit.xcodeproj/project.pbxproj +++ b/WSAudioKit.xcodeproj/project.pbxproj @@ -490,6 +490,7 @@ INFOPLIST_FILE = Source/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "-D DEBUG"; @@ -546,6 +547,7 @@ INFOPLIST_FILE = Source/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_SWIFT_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = co.whitesmith.WSAudioKit;