Coder Social home page Coder Social logo

kevindelord / audioplayermanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tschob/audioplayermanager

0.0 2.0 0.0 158 KB

Small Swift Wrapper and Queue-Manager around AVPlayer which let you play MediaPlayer items and stream songs from URLs.

License: MIT License

Ruby 3.39% Swift 95.56% Objective-C 1.05%

audioplayermanager's Introduction

AudioPlayerManager

Build Status CocoaPods compatible Carthage compatible License Platform Language: Swift 3.0

Feature

AudioPlayerManager is a small audio player which takes care of the AVPlayer setup and usage. It uses an internal queue to play multiple items automatically in a row. All path based items which are supported from AVPlayer can be used (MPMediaItems and remote URLs).

Requirements

  • iOS 8+
  • Xcode 8+

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks (10.9).

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate AudioPlayerManager into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'AudioPlayerManager'
end

Then, run the following command:

$ pod install

Usage

There two basic usages:

  • A singleton player which play one item at a time
AudioPlayerManager.shared.setup()
  • Multiple player instances which can be used at the same time
let audioPlayer = AudioPlayerManager.audioPlayer()

Setup

In both usage cases you need to setup() the player instance before using it.

AudioPlayerManager.shared.setup()

This will setup the AVAudioSession playback plus activation state and initialize the remote control events plus now playing info center configuration. If you want to modify the basic settings you can this after calling setup.

AudioPlayerManager.shared.setup()
AudioPlayerManager.shared.playingTimeRefreshRate = 1.0

If you want to reveive remote control events you simply have to pass the events from the app delegate to the audio player instace

override func remoteControlReceived(with event: UIEvent?) {
	AudioPlayerManager.shared.remoteControlReceivedWithEvent(event)
}

Playback

AudioPlayerManager can play local MPMediaItems and stream items from a remote URL. You can pass either one or multiple items to the player.

The following line will replace the current queue of the audio player with the chosen item. The playback will stop automatically if the item was played.

AudioPlayerManager.shared.play(url: self.trackUrl)

If you want to play multiple items you can pass an array and start index. The audio player will replace the current queue with the given array and jump right to the item at the given index. The queue allows the user to rewind also to items with a lower index than the start index.

let songs = (MPMediaQuery.songsQuery().items ?? [])
AudioPlayerManager.shared.play(mediaItems: songs, at: 5)

Author

tschob, Hans Seiffert

License

AudioPlayerManager is available under the MIT license.

audioplayermanager's People

Contributors

kevindelord avatar tschob avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.