RXAVPlayerKit 1.4.0

RXAVPlayerKit 1.4.0

Maintained by Ke Yang.



 
Depends on:
ReactiveObjC>= 0
CocoaLumberjack>= 0
 

  • By
  • Ke Yang

RXAVPlayerKit

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.