All Projects → jorgenhenrichsen → Swiftaudio

jorgenhenrichsen / Swiftaudio

Licence: mit
Audio player for iOS

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftaudio

Fradioplayer
A simple radio player framework for iOS, macOS, tvOS.
Stars: ✭ 183 (+14.38%)
Mutual labels:  audio, audio-player, avplayer, audio-library, cocoapods
Abmediaview
Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.
Stars: ✭ 79 (-50.62%)
Mutual labels:  audio, audio-player, avplayer
Swift Radio Pro
Professional Radio Station App for iOS!
Stars: ✭ 2,644 (+1552.5%)
Mutual labels:  audio, audio-player, avplayer
Modernavplayer
ModernAVPlayer is a persistence AVPlayer wrapper
Stars: ✭ 179 (+11.88%)
Mutual labels:  audio, avplayer, cocoapods
Fwplayer
A video player SDK for iOS, it is based on AVPlayer. https://se.linkedin.com/in/foks-huiwang, https://fokswang.wixsite.com/home
Stars: ✭ 321 (+100.63%)
Mutual labels:  audio, avplayer, cocoapods
React Cassette Player
Simple ReactJS HTML5 audio player component built with SVG icons from The Noun Project.
Stars: ✭ 93 (-41.87%)
Mutual labels:  audio, audio-player
Freemp
Free Media Player (FreeMp)
Stars: ✭ 97 (-39.37%)
Mutual labels:  audio, audio-player
Sbplayerclient
支持全格式的mac版视频播放器
Stars: ✭ 110 (-31.25%)
Mutual labels:  audio, audio-player
Swifty360player
iOS 360-degree video player streaming from an AVPlayer.
Stars: ✭ 118 (-26.25%)
Mutual labels:  avplayer, cocoapods
Audioplayermanager
⚠️ No longer maintained ⚠️ Small Swift Wrapper and Queue-Manager around AVPlayer which let you play MediaPlayer items and stream songs from URLs.
Stars: ✭ 78 (-51.25%)
Mutual labels:  audio-player, avplayer
Miniaudio
Single file audio playback and capture library written in C.
Stars: ✭ 1,889 (+1080.63%)
Mutual labels:  audio, audio-library
Libopenshot Audio
OpenShot Audio Library (libopenshot-audio) is a free, open-source project that enables high-quality editing and playback of audio, and is based on the amazing JUCE library.
Stars: ✭ 120 (-25%)
Mutual labels:  audio, audio-library
Mpd
Music Player Daemon
Stars: ✭ 1,289 (+705.63%)
Mutual labels:  audio, audio-player
Nymphcast
Audio and video casting system with support for custom applications.
Stars: ✭ 2,010 (+1156.25%)
Mutual labels:  audio, audio-player
Soundable
Soundable allows you to play sounds, single and in sequence, in a very easy way
Stars: ✭ 78 (-51.25%)
Mutual labels:  audio, cocoapods
Libaudiodecoder
The Cross-Platform Audio Decoder API
Stars: ✭ 114 (-28.75%)
Mutual labels:  audio, audio-library
Audio
Generic Go package designed to define a common interface to analyze and/or process audio data
Stars: ✭ 129 (-19.37%)
Mutual labels:  audio, audio-library
React Jplayer
Html5 audio and video player library for React
Stars: ✭ 128 (-20%)
Mutual labels:  audio, audio-player
Cscore
An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Stars: ✭ 1,768 (+1005%)
Mutual labels:  audio, audio-library
React Native Sound Player
Play sound file in ReactNative
Stars: ✭ 144 (-10%)
Mutual labels:  audio, audio-player

logo

SwiftAudio

Build Status Version codecov License Platform

SwiftAudio is an audio player written in Swift, making it simpler to work with audio playback from streams and files.

Example

To see the audio player in action, run the example project! To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 10.0+

Installation

CocoaPods

SwiftAudio is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftAudio', '~> 0.11.2'

Carthage

SwiftAudio supports Carthage. Add this to your Cartfile:

github "jorgenhenrichsen/SwiftAudio" ~> 0.11.2

Then follow the rest of Carthage instructions on adding a framework.

Usage

AudioPlayer

To get started playing some audio:

let player = AudioPlayer()
let audioItem = DefaultAudioItem(audioUrl: "someUrl", sourceType: .stream)
player.load(item: audioItem, playWhenReady: true) // Load the item and start playing when the player is ready.

To listen for events in the AudioPlayer, subscribe to events found in the event property of the AudioPlayer. To subscribe to an event:

class MyCustomViewController: UIViewController {

    let audioPlayer = AudioPlayer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        audioPlayer.event.stateChange.addListener(self, handleAudioPlayerStateChange)
    }
    
    func handleAudioPlayerStateChange(state: AudioPlayerState) {
        // Handle the event
    }
}

QueuedAudioPlayer

The QueuedAudioPlayer is a subclass of AudioPlayer that maintains a queue of audio tracks.

let player = QueuedAudioPlayer()
let audioItem = DefaultAudioItem(audioUrl: "someUrl", sourceType: .stream)
player.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.

When a track is done playing, the player will load the next track and update the queue, as long as automaticallyPlayNextSong is true (default).

Navigating the queue

All AudioItems 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:

player.next() // Increments the queue, and loads the next item.
player.previous() // Decrements the queue, and loads the previous item.
player.jumpToItem(atIndex:) // Jumps to a certain item and loads that item.
Manipulating the queue
 player.removeItem(at:) // Remove a specific item from the queue.
 player.removeUpcomingItems() // Remove all items in nextItems.

Configuring the AudioPlayer

Current options for configuring the AudioPlayer:

  • bufferDuration: The amount of seconds to be buffered by the player.
  • timeEventFrequency: How often the player should call the delegate with time progress events.
  • automaticallyWaitsToMinimizeStalling: Indicates whether the player should automatically delay playback in order to minimize stalling.
  • volume
  • isMuted
  • rate
  • audioTimePitchAlgorithm: This value decides the AVAudioTimePitchAlgorithm used for each AudioItem. Implement TimePitching in your AudioItem-subclass to override individually for each AudioItem.

Audio Session

Remember to activate an audio session with an appropriate category for your app. This can be done with AudioSessionController:

try? AudioSessionController.shared.set(category: .playback)
//...
// You should wait with activating the session until you actually start playback of audio.
// This is to avoid interrupting other audio without the need to do it.
try? AudioSessionController.shared.activateSession()

Important: If you want audio to continue playing when the app is inactive, remember to activate background audio: App Settings -> Capabilities -> Background Modes -> Check 'Audio, AirPlay, and Picture in Picture'.

Interruptions

If you are using the AudioSessionController for setting up the audio session, you can use it to handle interruptions too. Implement AudioSessionControllerDelegate and you will be notified by handleInterruption(type: AVAudioSessionInterruptionType). If 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. To disable interruption notifcations set isObservingForInterruptions to false.

Now Playing Info

The 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.

Additional properties for items can be set by accessing the setter of the nowPlayingInforController:

    let player = AudioPlayer()
    player.load(item: someItem)
    player.nowPlayingInfoController.set(keyValue: NowPlayingInfoProperty.isLiveStream(true))

The set(keyValue:) and set(keyValues:) accept both MediaItemProperty and NowPlayingInfoProperty.

The info can be forced to reload/update from the AudioPlayer.

    audioPlayer.loadNowPlayingMetaValues()
    audioPlayer.updateNowPlayingPlaybackValues()

The current info can be cleared with:

    audioPlayer.nowPlayingInfoController.clear()

Remote Commands

To enable remote commands for the player you need to populate the RemoteCommands array for the player:

audioPlayer.remoteCommands = [
    .play,
    .pause,
    .skipForward(intervals: [30]),
    .skipBackward(intervals: [30]),
  ]

These 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.

Custom handlers for remote commands

To supply custom handlers for your remote commands, just override the handlers contained in the player's RemoteCommandController:

let player = QueuedAudioPlayer()
player.remoteCommandController.handlePlayCommand = { (event) in
    // Handle remote command here.
}

All available overrides can be found by looking at RemoteCommandController.

Start playback from a certain point in time

Make your AudioItem-subclass conform to InitialTiming to be able to start playback from a certain time.

Author

Jørgen Henrichsen

License

SwiftAudio is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].