Swiftpack.co - Package - noreasonprojects/ModernAVPlayer

ModernAVPlayer

Swift 4.2 Build Status CocoaPods CocoaPods

ModernAVPlayer is a persistence AVPlayer wrapper

++ Cool features ++

  • Get 9 nice and relevant player states (playing, buffering, loading, loaded...)
  • Persistence player to resume playback after bad network connection even in background mode
  • Manage headphone interactions, call & siri interruptions, now playing informations
  • Add your own plug-in to manage tracking, events...
  • RxSwift compatible
  • Loop mode
  • Log available by domain

Menu

Requirements

  • iOS 10.0+
  • Xcode 11.0+
  • Swift 5.0+

In order to support background mode, append the following to your Info.plist:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

Installation

Swift Package Manager

Supported version: swift-tools-version:5.0

// Package.swift

import PackageDescription

let package = Package(
    name: "Sample",
    dependencies: [
        .package(url: "https://github.com/noreasonprojects/ModernAVPlayer", from: "X.X.X")
    ],
    targets: [
        .target(name: "Sample", dependencies: ["ModernAVPlayer"])
    ]
)

CocoaPods

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

$ gem install cocoapods

CocoaPods 1.3+ is required to build ModernAVPlayer.

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

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

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

Then, run the following command:

$ pod install

Getting started

Create media from URL

let media = ModernAVPlayerMedia(url: URL, type: MediaType)

Create media from AVPlayerItem

let media = ModernAVPlayerMediaItem(item: AVPlayerItem, type: MediaType, metadata: PlayerMediaMetadata)

Instanciate the wrapper

let player = ModernAVPlayer()

Load and play the media

player.load(media: media, autostart: true)

Track on repeat

player.loopMode = true

| ↓ State / Command → | loadMedia | play | pause | stop | seek | |:---------|:---------:|:--------:|:--------:|:--------:|:--------:| | Init | O | X | O | O | X | Loading | O | X | O | O | X | Loaded | O | O | O | O | O | Buffering | O | X | O | O | O | Playing | O | X | O | O | O | Paused | O | O | X | O | O | Stopped | O | O | O | X | O | WaitingNetwork | O | X | O | O | X | Failed | O | O | X | X | X

Advanced

Custom configuration

All player configuration are available from PlayerConfiguration protocol.
A default implementation ModernAVPlayerConfiguration is provided with documentation


Remote command

If using default configuration file ( swift useDefaultRemoteCommand = true), ModernAVPlayer use automatically all commands created by ModernAVPlayerRemoteCommandFactory class Documention available in ModernAVPlayerRemoteCommandFactory.swift file

Custom command

Use your own PlayerConfiguration implementation with

...
useDefaultRemoteCommand = false
...

Create an array of commands conforming to ModernAVPlayerRemoteCommand protocol.

let player = ModernAVPlayer(config: YourConfigImplementation())
let commands: [ModernAVPlayerRemoteCommand] = YourRemoteCommandFactory.commands
player.remoteCommands = commands

You can use existing commands from public ModernAVPlayerRemoteCommandFactory class.


Plugin

Use PlayerPlugin protocol to create your own plugin system, like tracking Plugin.


RxSwift

Instead of using delegate pattern, you can use rx to bind player attributes.

Setup

Use pod 'ModernAVPlayer/RxSwift' in the Podfile

Usage

let player = ModernAVPlayer()
let state: Observable<ModernAVPlayer.State> = player.rx.state

Communication

  • If you found a bug, make a pull request using Simple Audio template in the example section to demonstrate.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Github

link
Stars: 125

Dependencies

Used By

Total: 0

Releases

Dirk Hamer Syndrome - 2020-10-13 22:29:35

Microzyma - 2020-10-13 21:18:39

Antoine Béchamp avait raison.

[1.6.0] Basilic - 2020-06-02 07:35:20

read CHANGELOG.md

[1.5.2] Ease Yourself And Glide - 2020-05-30 09:24:40

read CHANGELOG.md

[1.5.1] The New Abnormal - 2020-05-30 09:23:02

read CHANGELOG.md

[1.5.0] Visions - 2020-02-09 02:55:48

  • Features:
    • Create media from an AVPlayerItem
    • Define custom item loaded asset keys
  • Fixes:
    • Fix not expected value on periodicTimeObserver
    • Remove some WaitingForNetworkState dead code
  • Improvement:
    • Create service to deliver AVPlayerItem
  • Breaking changes:
    • New itemLoadedAssetKeys attribut for PlayerConfiguration
    • PlayerConfiguration preferedTimescale was renamed as preferredTimescale
  • Dependencies:
    • [gem] Fastlane -> 2.141.0
    • [pod] Rx... -> 5.0.1
    • [pod] Swiftlint -> 0.38.2
    • [pod] SwiftyMocky -> 3.5.0

[1.4.0] Beverley Hills - 2019-11-06 01:48:28

  • Feature:
    • Support SPM
  • Fix:
    • Seek available on stream media
  • Break changes:
    • PlayerUnavailableActionReason enum changed
      • itemDurationNotSet was replaced by seekPositionNotAvailable
      • seekOverstepTime was replaced by seekOverstepPosition

[1.3.3] Steve Lacy - 2019-11-03 15:21:05

  • Features:
    • Seek media with a given offset
    • Seek position is bounded between 0 and current media end time
  • Demo:
    • New simple video example
  • Breaking change:
    • Remove useless ModernAVPlayerCurrentMedia protocol
  • Dependencies:
    • Update some gems

[1.3.2] Dongdaemun - 2019-10-31 16:20:15

  • Fixes:
    • Update player metadata access control
    • Remove useless travis command
    • Remove retain cycles
  • Demo:
    • New simple audio example