ModernAVPlayer is a persistence AVPlayer wrapper
ModernAVPlayeris a persistence
AVPlayerwrapper
From version 1.5.1, resume playback from background mode failed. If you have any suggestion, please help.
Use of mixWithOther AVAudiosession CategoryOptions is not a solution.
In order to support background mode, append the following to your
Info.plist:UIBackgroundModes audio
Supported version:
swift-tools-version:5.0
// Package.swiftimport 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 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
ModernAVPlayerinto your Xcode project using CocoaPods, specify it in your
Podfile:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks!target '' do pod 'ModernAVPlayer' end
Then, run the following command:
$ pod install
Create media from URL
swift let media = ModernAVPlayerMedia(url: URL, type: MediaType)Create media from AVPlayerItemswift let media = ModernAVPlayerMediaItem(item: AVPlayerItem, type: MediaType, metadata: PlayerMediaMetadata)Instanciate the wrapper
swift let player = ModernAVPlayer()Load and play the mediaswift player.load(media: media, autostart: true)Track on repeatswift 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
All player configuration are available from
PlayerConfigurationprotocol.
ModernAVPlayerConfigurationis provided with documentation
If using default configuration file (
swift useDefaultRemoteCommand = true), ModernAVPlayer use automatically all commands created by
ModernAVPlayerRemoteCommandFactoryclass Documention available in
ModernAVPlayerRemoteCommandFactory.swiftfile
Use your own
PlayerConfigurationimplementation withswift ... useDefaultRemoteCommand = false ...Create an array of commands conforming to
ModernAVPlayerRemoteCommandprotocol.swift let player = ModernAVPlayer(config: YourConfigImplementation()) let commands: [ModernAVPlayerRemoteCommand] = YourRemoteCommandFactory.commands player.remoteCommands = commands
You can use existing commands from public
ModernAVPlayerRemoteCommandFactoryclass.
Use
PlayerPluginprotocol to create your own plugin system, like tracking Plugin.
Instead of using delegate pattern, you can use rx to bind player attributes.
Setup
Use
pod 'ModernAVPlayer/RxSwift'in the Podfile
Usage
swift let player = ModernAVPlayer() let state: Observable = player.rx.state
Simple Audiotemplate in the example section to demonstrate.