Latest 1.0.0
Homepage https://github.com/ShowMax/SHMAVPlayerInterface
License Apache
Platforms ios 9.0, tvos 10.0
Dependencies RxSwift, RxCocoa
Frameworks AVFoundation
Authors

Swift
Platform
License

SHMAVPlayerInterface provides an easy-to-use interface for AVPlayer and AVPlayerItem. You can replace KVO, CMTime, media groups, and other unfriendly APIs.

The SHMAVPlayerInterface library provides a reactive API to observe important properties. SHMAVPlayerInterface also gives you a wrapper around AVPlayer to handle basic actions like play/pause and subtitles changes. You still retain full control over your AVPlayer.

SHMAVPlayerInterface uses RxSwift and RxCocoa libraries. If you are not familiar with reactive programming you should look at these libraries before using SHMAVPlayerInterface.

Installation

SHMAVPlayerInterface is available through CocoaPods.

Add the following line to your Podfile

pod 'SHMAVPlayerInterface'

Install dependencies

pod install

Getting Started

There are two options for using SHMAVPlayerInterface:

1) Import SHMAVPlayerInterface into your swift file

import SHMAVPlayerInterface

Option A) Create SHMAVPlayerInterface object and start using AVPlayer

let player: AVPlayer = ...
let playerInterface = SHMAVPlayerInterface(player: player)

playerInterface.play()

let subtitles = playerInterface.availableSubtitles
...

Option B) Or start observing AVPlayer (or AVPlayerItem) properties via reactive API.

IMPORTANT: If you use reactive extension for AVPlayer or AVPlayerItem then you must dispose your DisposeBag before you destroy AVPlayer or AVPlayerItem. If you don’t do it then application will crash.

let player: AVPlayer = ...

// Get update about playback position every second on main thread.
playerInterface.player.rx.playbackPosition(updateInterval: 1.0, updateQueue: nil)
  .subscribe(
      onNext: { position in

          print("Playback position: (position)")
      }
  )
  .disposed(by: bag)

Or you can combine these options as you like.

Documentation

Primary documentation is in the code comments. Every public API is commented.

Example code

This repository contains a real world example how to use this library. This example uses AVPlayerViewController with custom UI on iOS and with the default UI for tvOS.

To run the example project, clone the repo, and run pod install from the Example directory.

cd libs/SHMAVPlayerInterface/Example
pod install
open SHMAVPlayerInterface.xcworkspace

Authors

Showmax is an internet-based subscription video on demand service supplying an extensive catalogue of TV shows and movies. By leveraging relationships with major production studios from across the globe, Showmax delivers both world-class international content as well as the best of specialised local content. Showmax is accessible across a wide range of devices from smart TVs and computers to smartphones and tablets.

You can follow us at https://tech.showmax.com and/or https://twitter.com/ShowmaxDevs .

Status

This code is currently running in our production app. We are using the same pod as you see here. PRs are welcome.

License

SHMAVPlayerInterface is available under the Apache license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SHMAVPlayerInterface",
    "version": "1.0.0",
    "summary": "SHMAVPlayerInterface provides an easy-to-use interface for AVPlayer and AVPlayerItem. You can replace KVO, CMTime, media groups, and other unfriendly APIs.",
    "description": "SHMAVPlayerInterface provides an easy-to-use interface for AVPlayer and AVPlayerItem. You can replace KVO, CMTime, media groups, and other unfriendly APIs.nnThe SHMAVPlayerInterface library provides a reactive API to observe important properties. SHMAVPlayerInterface also gives you a wrapper around AVPlayer to handle basic actions like play/pause and subtitles changes. You still retain full control over your AVPlayer.",
    "homepage": "https://github.com/ShowMax/SHMAVPlayerInterface",
    "license": {
        "type": "Apache",
        "file": "LICENSE"
    },
    "authors": {
        "Showmax": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ShowMax/SHMAVPlayerInterface.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/showmaxdevs",
    "platforms": {
        "ios": "9.0",
        "tvos": "10.0"
    },
    "frameworks": "AVFoundation",
    "dependencies": {
        "RxSwift": [
            "~> 3.5.0"
        ],
        "RxCocoa": [
            "~> 3.5.0"
        ]
    },
    "source_files": [
        "Source/*.swift"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This