Core code implementation of mainstream Video Clients

Source: Internet
Author: User

Android native videoview style is really weak, but Netease news client with a large number of users actually use this, and truly served Netease's product manager. Currently, mainstream video websites, such as Youku, Tudou, iQiYi, and Sohu in China, and youtobe, the most representative outside China, are competing in the mobile Internet wave, the corresponding mobile video client is also released. I don't know from when, the client they launched basically unified the interactive style of the video playback interface. Of course, this interactive style is so popular that there must be an internal reason, that is, it allows the client to more cater to the user's operation habits, more intelligent. Now, as soon as you see the video playback interface, you will automatically slide the screen with your fingers left and right, expecting a specific interactive response.

Next we will briefly introduce several features of this interactive style.

1. the playback interface does not have a fixed horizontal or vertical screen, but automatically rotates the screen with the sensor and seamlessly connects the video to be played.

2. Slide your fingers to the screen left and quickly move back. Slide your fingers to the screen right and fast forward.

3. On the left half of the screen, the finger slides down to reduce the brightness. The finger slides up to increase the brightness. Exit the current page and restore the brightness.

4. The same seekbar can also be used to adjust the progress. The style is generally customized.

5. There will be two floating masks on the video, one on the top and the other on the bottom. Click the screen and the mask layer will be automatically displayed. Then, the screen will be automatically hidden.

6. the toast for adjusting the volume is generally customized.

7. Horizontal video screen, full screen display

After explaining some cool common features, I am moving towards these goals. We are glad that all these functions have been implemented, and the code has been put on GitHub. You can take a look at the effect and I believe it will give you a clear impression. Especially those who are suffering from implementation, it will be nice to see you. Take a look at the effect.

Some people suggested that they should talk about the basics and key points and paste some code. I think the suggestions are very good, so the code will be posted less in the future. If you want to view the source code, clone it directly to GitHub. If you have a good idea or the code is not well written, you are welcome to submit a pull request.

The following are some notes that you may need to pay attention.

I. Why is it difficult to rewrite videoview?

Videoview, like webview, is a heavyweight control in Android and takes time to buffer it. A large number of operations need to be used for rendering. Therefore, we can imagine that their memory pressure is still quite high, but with powerful support from the framework layer of Google's great gods, there is basically no need to worry about overhead. As an important control, videoview enables many mobile phone manufacturers to customize and modify it, which also leads to the fragmentation of videoview. The same video code may be displayed on different mobile phones. In addition, native videoview does not support full-screen playback. Instead, the video size is as large as the video size displayed on the mobile phone. In the case of ultra-screen playback, the video size scales proportionally according to the full-screen mode. Therefore, it is absolutely necessary to write a set of videoview for compatibility.

2. How is finger interaction implemented?

In Android, you can determine the finger position and sliding distance in two ways. One is to set the ontouchlistener callback listener, and the other is to use gesturedetector, then perform callback listening in ongesturelistener. I used the first method to implement different logic by judging the position of the finger falling and the movement of the gesture.

3. How to implement automatic hiding of the mask layer?

The video playback page is displayed by default. The mask layer is displayed. When the video starts to play, the mask layer is automatically hidden in five seconds. When the mask layer is not displayed, click the screen to bring up the mask layer. Click again to hide it. Both display and hide are accompanied by the execution of the animation, and the effect is good. Some people will say that a simple timer is not enough. I suggest you try to use less timer in Android encoding as much as possible. You can use the postdelayed (runnable R, long delaymillis) method of handler's delayed execution method.

IV. Implementation of seamless connection for horizontal and vertical screen Switching

Turn right when you go out and view the historical message "starting from Android screen rotation". You will understand it after reading it.


Well, today's dry goods are all here.

Source Code address: https://github.com/JackCho/AndroidVideoView

If it is helpful to you, you are welcome to subscribe to my public account --Android sharing (ID: android_share). The QR code below provides you with timely and high quality Android dry goods.

Core code implementation of mainstream Video Clients

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.