Latest 1.4.0
Homepage https://github.com/keyofvv/RXAVPlayerKit
License MIT
Platforms ios 8.0
Dependencies ReactiveObjC, CocoaLumberjack
Authors

CI Status
Version
License
Platform

Introduction

RXAVPlayerKit is a tiny wrapper based on AVPlayer and powered by ReactiveObjC, transfers player status via signals rather than delegates/blocks. It is designed to make AVPlayer-related logic clearer, codes more concise and easier to maintain and debug.

IMPORTANT: ReactiveObjC is required.

Usage

  • Initialize a RXAVPlayerView
#import <ReactiveObjC/ReactiveObjC.h>
#import <RXAVPlayerKit/RXAVPlayerKit.h>

self.playerView = [RXAVPlayerView new];
[someView addSubview:self.playerView];
  • Playback control
NSURL *videoUrl = [NSURL URLWithString:@"http://aliuwmp3.changba.com/userdata/video/45F6BD5E445E4C029C33DC5901307461.mp4"];
[self.playerView playWithURL:videoUrl];

// other controls:
[self.playerView play];
[self.playerView pause];
[self.playerView stop];
[self.playerView mute:true];
[self.playerView seekToTime:0];
  • Playback status updated
@weakify(self)
[[self.playerView.currentTimeUpdated deliverOnMainThread] subscribeNext:^(NSNumber *_Nullable x) {
    @strongify(self)
    NSTimeInterval currentTime = x.doubleValue;
    // do something to update currentTime label and/or slider...
}

[[[[self.playerView.durationUpdated deliverOnMainThread] distinctUntilChanged] ignore:@(NAN)] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    NSTimeInterval duration = x.doubleValue;
    // do something to update duration label... 
}];

[[self.playerView.playbackPlaying deliverOnMainThread] subscribeNext:^(NSURL * _Nullable x) {
    @strongify(self)
    // player is requested to play...
}];

[[self.playerView.playbackPaused deliverOnMainThread] subscribeNext:^(NSURL * _Nullable x) {
    @strongify(self)
    // player is paused...
}];

[[self.playerView.playbackStopped deliverOnMainThread] subscribeNext:^(NSURL * _Nullable x) {
    @strongify(self)
    // player is stopped and currentTime is ZERO...
}];

[[self.playerView.playbackEnded deliverOnMainThread] subscribeNext:^(NSURL * _Nullable x) {
    @strongify(self)
    // player has played to end...
}];

[[self.playerView.playbackStalled deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // player is stalled for buffering...
}];

[[self.playerView.muteStatusUpdated deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // player (not the device) is muted or unmuted;
}];

[[[self.playerView.volumeUpdated deliverOnMainThread] distinctUntilChanged] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // volume of player (not the device) is changed...
}];
  • Seek operations
@weakify(self)
[[self.playerView.seekStarted deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // player started to seek...
}];

[[self.playerView.seekCompleted deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // seek operation is completed...
}];

[[self.playerView.seekInterrupted deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    // last seek operation is interrupted by current seek operation...
}];
  • Error raised
@weakify(self)
[[self.playerView.errorRaised deliverOnMainThread] subscribeNext:^(NSError * _Nullable x) {
    @strongify(self)
    // do something to handle error...
}];
  • Data transfer updated
@weakify(self)
[[self.playerView.downloadSpeedUpdated deliverOnMainThread] subscribeNext:^(NSNumber * _Nullable x) {
    @strongify(self)
    long long bytesPerSecond = x.longLongValue;
    // do something...
}];
  • Others
@weakify(self)
[[self.playerView.audioSessionRouteChanged deliverOnMainThread] subscribeNext:^(NSDictionary * _Nullable x) {
    @strongify(self)
    // headphones plugged-in/out...
}];

There are other signals available, please refer to example demo.

Example

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

Requirements

Installation

RXAVPlayerKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'RXAVPlayerKit'

Author

Ke Yang, [email protected]

License

RXAVPlayerKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RXAVPlayerKit",
    "version": "1.4.0",
    "summary": "RXAVPlayerKit is a tiny wrapper based on AVPlayer and powered by ReactiveObjC.",
    "description": "RXAVPlayerKit transfers status via signals rather than delegates or blocks. It is designed to make media playback related logic clearer, codes more concise and easier to maintain and debug.",
    "homepage": "https://github.com/keyofvv/RXAVPlayerKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ke Yang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/keyofvv/RXAVPlayerKit.git",
        "tag": "1.4.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "RXAVPlayerKit/Classes/**/*",
    "dependencies": {
        "ReactiveObjC": [],
        "CocoaLumberjack": []
    }
}

Pin It on Pinterest

Share This