SwiftyPlayer
A comfortable player used to manage the playback and timing of a media asset. Swift Player based on the AVPlayer and give to you a really comfortable interface for general player, timing and buffering state observations. You can easy create custom interface to control the player’s transport behavior such as its ability to play, pause, change the playback rate, and seek to various points in time within the media’s timeline. And you can also set AVPlayerViewControllerPlayer as default interface. You can use an SwiftyPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming.
Features
- Easy to use
- Support all actions for player's control
- General State Observations through methods of delegate
- Timed State Observations through methods of delegate
- Buffering State Observations through methods of delegate
- Using all power AVPlayer
- Ability to set AVPlayerViewController as default interface
Usage
- Import
SwiftyPlayer
module to yourViewController
class
import SwiftyPlayer
- Instantiate and set
playerLayer
andvideoGravity
let player = Player()
player.setPlayer(to: playerLayerView.playerLayer)
playerLayerView.playerLayer.videoGravity = .resizeAspect
- Set
delegate
andbufferingDelegate
if need
player.delegate = self
player.bufferingDelegate = self
- Set the
URL
orAVPlayerItem
orAVAsset
to player
player.URL = playerURL
//or
player.playerItem = playerItem
//or
player.asset = playerAsset
- Create a custom interface with controls and set relevant commands to
SwiftyPlayer
@IBAction func play() {
player.play()
}
@IBAction func pause() {
player.pause()
}
@IBAction func didSlide(_ sender: UISlider) {
player.seek(to: sender.value, shouldAutoPlay: true)
}
- Add a handler for
PlayerDelegate
if need
func player(_ player: Player, didUpdateTime timePlayed: Double) {
// to handle timePlayed
print(timePlayed)
}
func player(_ player: Player, didChangePlaybackState playbackState: PlaybackState) {
// to handle playbackState
print(playbackState)
}
func playerDidPlayToEnd(_ player: Player) {
// to handle player's event
}
func playerDidUpdatePlayerItem(_ player: Player) {
// to handle player's item
}
- Add a handler for
PlayerBufferingDelegate
if need
func player(_ player: Player, didChangeBufferingState bufferingState: BufferingState) {
// to handle bufferingState
print(bufferingState)
}
func playerDidUpdateBufferingProgress(_ player: Player) {
// to handle bufferingProgress
print(player.bufferingProgress)
}
Installation with CocoaPods
To install via CocoaPods
add this lines to your Podfile
. You need CocoaPods
v. 1.3.1 or higher
$ gem install cocoapods
Podfile
To integrate SwiftyPlayer
into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'TargetName' do
pod 'SwiftyPlayer', '~> 1.0'
end
Then, run the following command:
$ pod install
License
SwiftyPlayer is available under the MIT license. See the LICENSE file for more info.