Android Dragvideo Implement any drag-and-drop method when playing video _android

Source: Internet
Author: User

Android Dragvideo Implement any drag when playing video

Dragvideo

Alpha to Drag the "video" when Playing

A scheme that can be dragged when playing video

Why do you have this project?

Often watch movies on Archie website, see if sliding cover up the play window, then there is a small play interface at the bottom. And this playback interface, can be arbitrarily dragged. It feels so cool.

Since the web can be implemented, think of the mobile end of the device, whether it can achieve this effect, so there is ...

Effect Chart:


—————— >

Realization idea: 1, play the video view choice Textureview

2, ListView under the cover of the custom Viewdraghelper, when playing video, through the custom viewdraghelper to drag Textureview

3, the gradual processing, so that the two view text can alternately display

4, when the Textureview to the lower right, control in the horizontal direction of drag, to the left edge, if you slide again, destroy Textureview code analysis:

The following points should be noted about Viewdraghelper:

1.viewdraghelper.callback is a bridge between Viewdraghelper and view (this view is generally referred to as the container that holds the child view-Parentview).

The example of 2.ViewDragHelper is created by a static factory method; You can specify the direction of the drag; Viewdraghelper can detect whether the edges are touched;

The 3.ViewDragHelper does not directly affect the view that is being dragged, but the child view in the View container in which it is controlled can be dragged, and if you want to specify the behavior of a child view, you need to find a way in the callback.

The essence of 4.ViewDragHelper is to analyze the motionevent parameters of Onintercepttouchevent and ontouchevent, and then to change the position of the dragged child view in a container according to the results of the analysis ( by offsettopandbottom (int offset) and offsetleftandright (int offset), he can determine which child view is currently dragged when touching;

5. Although the Viewdraghelper instance method. Viewdraghelper Create (ViewGroup forparent, Callback CB) You can specify an object that is viewdraghelper to handle the drag event. However, the design of the Viewdraghelper class determines that it is suitable for inclusion in a custom viewgroup, instead of using Viewdraghelper for view containers on any one layout.

1. Initialization of custom Customviewdraghelper

Viewdraghelper is generally used within a custom viewgroup, such as the following customize a class Dragvideoview directly inherited from ViewGroup, Inside the Dragvideoview there is a mdraghelper as a member variable:

Create a viewdraghelper with a callback interface, and here's the myhelpercallback, which are some of the basic ways to use
The handling of the drag behavior is given in the comment



The above callback works when Mainactivity calls the Setcallback method of Viewdraghelper. When you click on the Item List page (the first to display the ListView interface), call the PlayVideo () method, where the Dragvideoview.show method is used to begin displaying Dragvideoview. Then the video starts to play and we can drag and drop it.


So in the process of dragging, we'll rewrite the Ontouchevent method in Dragvideoview, as follows

In the end, we call the Mdraghelper.processtouchevent (event), which is our custom customviewdraghelper class, and this method has not changed, Is the Processtouchevent method of Viewdraghelper.




Summarize this method

The Action_down, Action_move, and action_up events were processed in Processtouchevent:

1. Call the Trycaptureview method in the callback interface in Action_down to see if the current touch view allows dragging

2. In Action_move, the view coordinates are changed, the Onviewpositionchanged method in the callback interface is invoked, the view is layout according to the coordinate information, through Viewhelper Setscalex in this class, Setscaley method, which realizes that the view is scaled proportionally in xy coordinates during the dragging process;

3. After action_up call the Onviewreleased method in the callback interface, an important task in this method is to realize the automatic sliding of view after the Action_up event. This is mainly used in the Viewdraghelper Smoothslideviewto method

Then reach the Forcesettlecapturedviewat method.

The top start is the Mscroller in the Viewdraghelper, in the sliding process, by rewriting the Computescroll method, you can use Viewcompat.postinvalidateonanimation (this) method to Redraw view

Finally, due to the textureview of the display video in the drag-and-drop process, the change process of the current textureview is monitored by setting the textureview.surfacetexturelistener.


Item Download Address:http://xiazai.jb51.net/201612/yuanma/DragVideo-master (jb51.net). rar

Thank you for reading, I hope to help you, thank you for your support for this site!

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.