{"id":2134444,"url":"https://github.com/jorgenhenrichsen/SwiftAudio","last_synced_at":"2025-07-13T12:31:14.388Z","repository":{"id":44943683,"uuid":"125512014","full_name":"jorgenhenrichsen/SwiftAudio","owner":"jorgenhenrichsen","description":"Audio player for iOS","archived":false,"fork":false,"pushed_at":"2021-09-27T17:12:00.000Z","size":2710,"stargazers_count":220,"open_issues_count":51,"forks_count":84,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-09T11:58:40.775Z","etag":null,"topics":["audio","audio-library","audio-player","audio-streaming","avplayer","cocoapods","ios","streaming-audio","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jorgenhenrichsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-16T12:15:06.000Z","updated_at":"2024-04-02T10:05:01.000Z","dependencies_parsed_at":"2022-08-30T16:50:53.977Z","dependency_job_id":null,"html_url":"https://github.com/jorgenhenrichsen/SwiftAudio","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgenhenrichsen%2FSwiftAudio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgenhenrichsen%2FSwiftAudio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgenhenrichsen%2FSwiftAudio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgenhenrichsen%2FSwiftAudio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jorgenhenrichsen","download_url":"https://codeload.github.com/jorgenhenrichsen/SwiftAudio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225882080,"owners_count":17539107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","audio-library","audio-player","audio-streaming","avplayer","cocoapods","ios","streaming-audio","swift"],"created_at":"2024-01-21T23:53:03.182Z","updated_at":"2024-11-22T10:30:25.546Z","avatar_url":"https://github.com/jorgenhenrichsen.png","language":"Swift","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"![logo](Images/original-horizontal.png)\n\n## ⚠️ This repo is not actively maintained ⚠️\nPlease do not use this in production applications.\nA fork of this package can be found [here](https://github.com/DoubleSymmetry/SwiftAudioEx).\n\n# SwiftAudio\n\n[![Build Status](https://app.bitrise.io/app/3d3ac2ba8d817235/status.svg?token=PHIPu3oMde5GdQEOZ1Ilww\u0026branch=master)](https://app.bitrise.io/app/3d3ac2ba8d817235)\n[![Version](https://img.shields.io/cocoapods/v/SwiftAudio.svg?style=flat)](http://cocoapods.org/pods/SwiftAudio)\n[![codecov](https://codecov.io/gh/jorgenhenrichsen/SwiftAudio/branch/master/graph/badge.svg)](https://codecov.io/gh/jorgenhenrichsen/SwiftAudio)\n[![License](https://img.shields.io/cocoapods/l/SwiftAudio.svg?style=flat)](http://cocoapods.org/pods/SwiftAudio)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftAudio.svg?style=flat)](http://cocoapods.org/pods/SwiftAudio)\n\nSwiftAudio is an audio player written in Swift, making it simpler to work with audio playback from streams and files.\n\n## Example\n\nTo see the audio player in action, run the example project!\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\niOS 10.0+\n\n## Installation\n\n### CocoaPods\nSwiftAudio is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SwiftAudio', '~\u003e 0.11.2'\n```\n\n### Carthage\nSwiftAudio supports [Carthage](https://github.com/Carthage/Carthage). Add this to your Cartfile:\n```ruby\ngithub \"jorgenhenrichsen/SwiftAudio\" ~\u003e 0.11.2\n```\nThen follow the rest of Carthage instructions on [adding a framework](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).\n\n## Usage\n\n### AudioPlayer\nTo get started playing some audio:\n```swift\nlet player = AudioPlayer()\nlet audioItem = DefaultAudioItem(audioUrl: \"someUrl\", sourceType: .stream)\nplayer.load(item: audioItem, playWhenReady: true) // Load the item and start playing when the player is ready.\n```\n\nTo listen for events in the `AudioPlayer`, subscribe to events found in the `event` property of the `AudioPlayer`.\nTo subscribe to an event:\n```swift\nclass MyCustomViewController: UIViewController {\n\n    let audioPlayer = AudioPlayer()\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        audioPlayer.event.stateChange.addListener(self, handleAudioPlayerStateChange)\n    }\n    \n    func handleAudioPlayerStateChange(state: AudioPlayerState) {\n        // Handle the event\n    }\n}\n```\n\n#### QueuedAudioPlayer\nThe `QueuedAudioPlayer` is a subclass of `AudioPlayer` that maintains a queue of audio tracks.\n```swift\nlet player = QueuedAudioPlayer()\nlet audioItem = DefaultAudioItem(audioUrl: \"someUrl\", sourceType: .stream)\nplayer.add(item: audioItem, playWhenReady: true) // Since this is the first item, we can supply playWhenReady: true to immedietaly start playing when the item is loaded.\n```\n\nWhen a track is done playing, the player will load the next track and update the queue, as long as `automaticallyPlayNextSong` is `true` (default).\n\n##### Navigating the queue\nAll `AudioItem`s are stored in either `previousItems` or `nextItems`, which refers to items that come prior to the `currentItem` and after, respectively. The queue is navigated with:\n```swift\nplayer.next() // Increments the queue, and loads the next item.\nplayer.previous() // Decrements the queue, and loads the previous item.\nplayer.jumpToItem(atIndex:) // Jumps to a certain item and loads that item.\n```\n\n##### Manipulating the queue\n```swift\n player.removeItem(at:) // Remove a specific item from the queue.\n player.removeUpcomingItems() // Remove all items in nextItems.\n```\n\n### Configuring the AudioPlayer\nCurrent options for configuring the `AudioPlayer`:\n- `bufferDuration`: The amount of seconds to be buffered by the player.\n- `timeEventFrequency`: How often the player should call the delegate with time progress events.\n- `automaticallyWaitsToMinimizeStalling`: Indicates whether the player should automatically delay playback in order to minimize stalling.\n- `volume`\n- `isMuted`\n- `rate`\n- `audioTimePitchAlgorithm`: This value decides the `AVAudioTimePitchAlgorithm` used for each `AudioItem`. Implement `TimePitching` in your `AudioItem`-subclass to override individually for each `AudioItem`.\n\n### Audio Session\nRemember to activate an audio session with an appropriate category for your app. This can be done with `AudioSessionController`:\n```swift\ntry? AudioSessionController.shared.set(category: .playback)\n//...\n// You should wait with activating the session until you actually start playback of audio.\n// This is to avoid interrupting other audio without the need to do it.\ntry? AudioSessionController.shared.activateSession()\n```\n\n**Important**: If you want audio to continue playing when the app is inactive, remember to activate background audio:\nApp Settings -\u003e Capabilities -\u003e Background Modes -\u003e Check 'Audio, AirPlay, and Picture in Picture'.\n\n#### Interruptions\nIf you are using the `AudioSessionController` for setting up the audio session, you can use it to handle interruptions too.\nImplement `AudioSessionControllerDelegate` and you will be notified by `handleInterruption(type: AVAudioSessionInterruptionType)`.\nIf you are storing progress for playback time on items when the app quits, it can be a good idea to do it on interruptions as well.\nTo disable interruption notifcations set `isObservingForInterruptions` to `false`.\n\n### Now Playing Info\nThe `AudioPlayer` can automatically update `nowPlayingInfo` for you. This requires `automaticallyUpdateNowPlayingInfo` to be true (default), and that the `AudioItem` that is passed in return values for the getters. The `AudioPlayer` will update: artist, title, album, artwork, elapsed time, duration and rate.\n\nAdditional properties for items can be set by accessing the setter of the `nowPlayingInforController`:\n```swift\n    let player = AudioPlayer()\n    player.load(item: someItem)\n    player.nowPlayingInfoController.set(keyValue: NowPlayingInfoProperty.isLiveStream(true))\n```\nThe set(keyValue:) and set(keyValues:) accept both `MediaItemProperty` and `NowPlayingInfoProperty`.\n\nThe info can be forced to reload/update from the `AudioPlayer`.\n```swift\n    audioPlayer.loadNowPlayingMetaValues()\n    audioPlayer.updateNowPlayingPlaybackValues()\n```\nThe current info can be cleared with:\n```swift\n    audioPlayer.nowPlayingInfoController.clear()\n```\n\n### Remote Commands\nTo enable remote commands for the player you need to populate the RemoteCommands array for the player:\n```swift\naudioPlayer.remoteCommands = [\n    .play,\n    .pause,\n    .skipForward(intervals: [30]),\n    .skipBackward(intervals: [30]),\n  ]\n```\nThese commands will be activated for each `AudioItem`. If you need some audio items to have different commands, implement `RemoteCommandable` in a custom `AudioItem`-subclass. These commands will override the commands found in `AudioPlayer.remoteCommands` so make sure to supply all commands you need for that particular `AudioItem`.\n\n#### Custom handlers for remote commands\nTo supply custom handlers for your remote commands, just override the handlers contained in the player's `RemoteCommandController`:\n```swift\nlet player = QueuedAudioPlayer()\nplayer.remoteCommandController.handlePlayCommand = { (event) in\n    // Handle remote command here.\n}\n```\nAll available overrides can be found by looking at `RemoteCommandController`.\n\n### Start playback from a certain point in time\nMake your `AudioItem`-subclass conform to `InitialTiming` to be able to start playback from a certain time.\n\n## Author\n\nJørgen Henrichsen\n\n## License\n\nSwiftAudio is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgenhenrichsen%2FSwiftAudio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjorgenhenrichsen%2FSwiftAudio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgenhenrichsen%2FSwiftAudio/lists"}