iOS Multi player Package

Source: Internet
Author: User

This year in the live broadcast business encountered some problems, that is, in a set of player UI needs a number of different players (Avplayer, Ijkplayer, Aliplayer) support, according to the abtest switch to switch the specific use of which player, and also to the player log statistics.
The first thing you can think of is the need to encapsulate a unified interface for different players, and for the UI, there is no need to have a relationship with which player is currently manipulated.


Multi-player architecture. jpg

Where player protocal is a key

@protocolVideoplaybackprotocal <NSObject>@property (nonatomic, assign, setter=setdelegate:)ID<LivePlaybackEventListener>Delegate;-(void) Addplaybackeventlistener: (ID<LivePlaybackEventListener>) listener;-(void) Removeplaybackeventlistener: (ID<LivePlaybackEventListener>) listener; @property (nonatomic, Strong,ReadOnly) UIView *view; @property (nonatomic, assign,ReadOnly) Cmtime currentplaybacktime; @property (nonatomic, assign,ReadOnly) cmtime duration; @property (nonatomic, assign,ReadOnly) Nsurl *Currentplayurl, @property (nonatomic, assign,ReadOnly) BOOL supportsrtmp;- (void) Stopduetolivedidend;- (void) resume;- (void) pause;- (void) replay;- (void) Reload;- (void) Startplayingwithplayinfo: (nsurl*) URL;- (void) shutdown;- (void) Seektoprogress: (Double) ProgressEvent:(playerevent)Event;-(BOOL) isplaying;@end

The three players then perform their respective implementations of the interface. This way, for Viewcontroller, the player is a id<videoplaybackprotocal>, and the player can pause and play various actions. Which player is intended to use, it is easy and simple to instantiate the id<videoplaybackprotocal> into which player is implemented.

Where the listener is a delegate, when the player appears to play, playback errors and other events, listener will be registered listener objects broadcast, currently need to register viewcontroller and logger, The UI receives a broadcast to make changes to the graphical interface, and logger is responsible for uploading the event statistics to the log server. This broadcaster uses a observe to ensure that the NSHashTable * _listeners; broadcast is registered as a weak reference, and then iterates through the observe to make delegate calls, for example:

-(void) Videoplayercontroller: (ID< videoplaybackprotocal >) Playercontroller Didfailwitherror: (nserror *) error Playerlog: (nsdictionary *) playerlog{    [self _enumeratelisteners:^ ( ID Listener, Nsuinteger idx) {        if  ([listener Respondstoselector:_cmd]) {            [listener Videoplayercontroller: Playercontroller Didfailwitherror:error Playerlog:playerlog];        }    }];}

 

iOS Multi player Package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.