Android barrage frame dark flame basic usage

Today, I will share the learning experience of the Android barrage framework (danmaku flamemaster) open source by BiliBili.

I introduced the whole framework into the project in the form of model, which is more convenient to observe the source code. It can also be injected through dependency

Let's start with the renderings I want to make:

Page analysis

From the above figure, the whole UI is divided into three layers. The bottom is the video layer, the middle is the barrage layer, and the top is the control layer. Now most of the mainstream video live broadcasting software in the market are layered like this. The difference is that if it is live broadcasting, there may be another interactive layer to display check-in information and gift information. Since it is layered, I will directly use FrameLayout to implement the frame layout. Paste my layout file:

Layout of control layer:

After writing the layout, first write an initialization method:

Then paste the implementation of the drawing filler, which mainly realizes the effect of arranging pictures and text together

Under the class basedanmaku, the basic movement form of the barrage is defined: type_ SCROLL_ RL、TYPE_ SCROLL_ LR、TYPE_ FIX_ TOP、TYPE_ FIX_ Bottom and type_ SPECIAL。 That is, right in and left out, left in and right out (reverse barrage), top barrage, bottom barrage and advanced barrage. (in addition, there are script bullets) during initialization, you need to pass in a unique bullet context danmukucontext to initialize some settings through the context. The bullet screen resource is saved in XML file. The approximate format is as follows:

The header information does not need much attention. Let's look at the specific meaning of the P corresponding parameter under the D tag:

First: the time when the barrage appeared

Second: barrage type (1. Right to left; 6. Left to right; 5. Top barrage; 4. Bottom barrage; 7. Advanced barrage; 8. Script barrage ')

Third: font size

Fourth: color

Fifth: timestamp

Sixth: barrage pool ID

Seventh: user hash value

Eighth: barrage ID

The following is the specific analysis code of the barrage

Specific analysis scheme:

After the barrage resources are loaded, the prepare() method of mdvdanmuku is called to perform the preparation. When it is ready, drawhandler is called Prepared method in callback() callback. Then the barrage is officially started in this prepared method. The calling sequence is as follows:

Then execute the prepare () method under danmukuview

The communication between processes is realized through this handler

handler. setConfig(config);

handler. setParser(parser);

handler. setCallback(mCallback);

handler. prepare();-》 It will ask the handler to send a message to perform the real preparation

There is a callback in drawhandler

Real preparation

The above is the starting and calling process of barrage view.

So, how to add barrage pinch? Yuanfang, what do you think? (TM, how do I know what I think) look below

The above is the dark flame of Android barrage framework introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>