The preamble to this article is:LNDanmakuMaster
LNDanmakuPlayer is the most important component of LNDanmakuMaster. This component should have the most code in the entire framework; Other major components usually come with Abstract support definitions, but LNDanmakuPlayer does not, which means it is not replaceable.
LNDanmakuPlayer structure
LNDanmakuPlayer has similar responsibilities to Controller in that it does not display content or update data; More often than not, he just calls the shots:
@interface LNDanmakuPlayer ()
<
LNDanmakuClockDelegate,
LNDanmakuContrainerViewDelegate,
LNDanmakuAbstractDispatcherDelegate,
LNDanmakuAbstractDispatcherSmoothGrainDataSource
>
@property (nonatomic, strong) LNDanmakuClock *clock;
@property (nonatomic, strong) LNDanmakuContainerView *containerView;
@property (nonatomic, strong) NSMutableArray<LNDanmakuAbstractTrackController *> *trackControllerMArr;
@property (nonatomic, strong) LNDanmakuDispatcher *dispatcher;
@property (nonatomic, strong) NSMutableArray <id<LNDanmakuClockDelegate>> *clockDelegateMArr;
@property (nonatomic, assign) LNDanmakuPlayerStatus status;
@property (nonatomic, strong) LNDanmakuPool *layerPool;
@property (nonatomic, strong) LNDanmakuPool *viewPool;
@property (nonatomic, strong) NSMutableArray <LNDanmakuTrackGroup *> *trackGroupMArr;
@property (nonatomic, strong) NSMutableSet <LNDanmakuAbstractTrackController *> *trackControllerNoRepeatMSet;
@property (nonatomic, assign) NSInteger maxSmoothGrainNum;
@property (nonatomic, assign) NSInteger restSmoothGrainNum;
@end
Copy the code
LNDanmakuPlayer work covers:
- Contains: Clock, containerView, trackController, Pool, trackGroup and other components.
- Implement: Clock, containerView, Dispatcher proxy and data source
- In addition, I am also responsible for one-to-many forwarding of clock signal, playback state maintenance, repeat check, throughput limit (maxSmoothGrainNum), bullet screen recovery and other work.
- As the facade class of LNDanmakuMaster, LNDanmakuPlayer needs to provide various control methods to the outside world. In order to divide the responsibilities of these methods, I have divided it into categories, including the default class: (Track), (Data), (Control), (TrackGroup), (Recover) five categories, each category provides the purpose of the method see the following detailed table.
Category name | role |
---|---|
(a) | Default categories that define other components to use and maintain player state. |
(Track) | Control track insertion and removal. |
(Data) | Control the data insertion and view reuse of barrage. |
(Control) | Control of Player playing state includes four basic control methods: start, pause, resume and end. The method of emptying each sub-component; A method for removing a single bullet barrage. |
(TrackGroup) | Special category of track group, including: insert and remove track group; Insert barrage into track group. |
(Recover) | After the restore operation special categories: LNDanmakuMaster support video seek quickly restore function, restore function refers to the video from a point in time after switching to another point in time, barrage player can instantly will show the barrage of the state of the switch to the corresponding time points, rather than empty after coming from the right side again to the central (introduces) after this feature. |
LNDanmakuPlayer works
LNDanmakuPlayer has more logic to implement. Here we describe all the processes that a common bullet screen goes through after entering LNDanmakuPlayer to string the Player together with other components described previously.
Note: remove the prefix LNDanmaku from all the following nouns; Ignore the case of the track group for the moment; The track used in Player is the most common kind of horizontal track.
Stage 1: Placement stage
- We have a bullet-screen model from the network, which may be segmented using HTTP or embedded in the audio and video stream. We don’t care about the source, but we are sure it is an NSObject object called XXModel.
- A dedicated danmaku factory produces an Attributes wrapper for the XXModel, placing the XXModel on the customObj property. The factory is business related, so it is not in the LNDanmakuMaster framework.
- The Attributes are released into the Player (usually the video playback progress is constantly generating callbacks and releasing playable bullets).
- The Player does not handle the barrage itself and passes it on to the Dispatcher.
- After the Dispatcher receives the Attributes, the Attributes are placed at the end of the queue, which is the queue that distinguishes between high and low priorities.
Phase 2: Update phase
- The enabled Clock generates the next update signal.
- The Player receives the update signal and receives a small amount of “elapsed time” in the signal. This time is the interval since the last clock signal. The Player forwards this signal and time information to its own TrackControllers and Dispatchers (in a fixed order).
- After receiving the signal, the TrackController updated the existing track, deducted the “elapsed time” of the signal from their survival time, and used its own track to rearrange the positions of these shells.
- After receiving the signal, the Dispatcher traverses the track list of Player, then finds the track that can put the first barrage of his team, and puts the first barrage of his team on the track.
- The TrackController receives the live barrage, places the presentView/presentLayer of the barrage on ContainerView, and updates the barrage in subsequent cycles as it updates any other barrage.
Phase 3: Uninstallation phase
- In phase 2, when the TrackController is updated, you will encounter cartridges that live longer than the preset time.
- The TrackController calls ContainerView to remove the barrage and remove it from its storage structure, and the proxy gives the Player an unload callback.
- After receiving the unload callback from the track controller, the Player retrieves Attributes’ presentLayer/presentView into the Pool and releases Attributes.
In addition to TrackController unload callbacks, the Dispatcher’s overflow discard, manual removal, and so on also perform Attributes collection.
conclusion
LNDanmakuPlayer is a facade class that encapsulates other components and provides call methods and timing proxies. Once a Player is built, all operations related to the bullet screen can be done by manipulating the Player without interacting with other internal components.
conclusion
At this point, all the components of the LNDanmakuMaster framework are covered. In addition to the components described in the base documentation, LNDanmakuMaster has some additional strategies or animations: Computation of distribution policies, animation of POP, throughput control policies, etc., are not required to use the framework, so I’ll leave them out here as options.
Finally, thank you for reading my article and for using my framework.