Skip to content

Commit

Permalink
Add SPM and CococPod spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Nov 25, 2020
1 parent 14a31cf commit 213e195
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 16 deletions.
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"])
]
)
63 changes: 48 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
# 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.

This repo accompanies a blog post [which can be found here](http://blog.jaredsinclair.com/post/149892449150/avassetresourceloaderdelegate).

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.

Expand All @@ -37,6 +73,3 @@ Delete and reinstall the app to clear out the scratch file (or change the hard-c

<img src="https://raw.githubusercontent.com/jaredsinclair/sodes-audio-example/master/screenshot.png" width="375">

## 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.
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
15 changes: 15 additions & 0 deletions WSAudioKit.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
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
2 changes: 2 additions & 0 deletions WSAudioKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 213e195

Please sign in to comment.