Reprint please the head source link and the tail two-dimensional code together reprint, this article from countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/53638896
Objective
Project is open source to my github:https://github.com/hejunlin2013/dragvideo
Dragvideo
A Method to Drag the video when Playing video
A solution that can be dragged while playing a video
Why is this project
I often watch movies on the Iqiyi website and see that if the swipe obscures the playback window, there is a small playback interface at the bottom. And this playback interface, can be arbitrarily dragged. It feels cool.
Since the web-side can be realized, think about the mobile device, whether it can also achieve this effect, so there is ...
:
—————— >
Implementation ideas:
- 1, play the video view select Textureview
- 2. Under the ListView, cover the custom Viewdraghelper, and when playing video, drag through custom Viewdraghelper Textureview
- 3, the gradient processing, so that the two view text can be displayed alternately
- 4, when the Textureview reached the lower right, control in the horizontal direction of the drag, reached the left edge, if you swipe again, destroy Textureview
Code Analysis:
There are several points to note about Viewdraghelper:
- Viewdraghelper.callback is the bridge between the Viewdraghelper and the view (this view is usually the container that holds the child view, i.e. Parentview);
- An instance of Viewdraghelper is created by a static factory method; You can specify the direction of the drag;
- Viewdraghelper can detect whether to reach the edge;
- Viewdraghelper is not directly acting on the view to be dragged, but the child view in the container that controls it can be dragged, if you want to specify the behavior of a sub-view, you need to find a way in callback;
- The essence of Viewdraghelper is to analyze the motionevent parameters of Onintercepttouchevent and ontouchevent, and then change the position of the dragged sub-view in a container based on the results of the analysis ( By means of offsettopandbottom (int offset) and offsetleftandright (int offset), he can determine which sub-view is currently being dragged while touching.
- Although the Viewdraghelper instance method viewdraghelper Create (ViewGroup forparent, Callback CB) can specify an object to be Viewdraghelper handle the drag event, However, the design of the Viewdraghelper class determines its applicability to being included in a custom viewgroup, rather than using viewdraghelper for a view container on any layout.
1. Initialization of a custom Customviewdraghelper
Viewdraghelper is typically used internally in a custom viewgroup, such as the following to customize a class Dragvideoview that inherits directly from ViewGroup, Inside the Dragvideoview there is a mdraghelper as a member variable:
Create a viewdraghelper with callback interface, here is the use of myhelpercallback, these are some basic use method
The handling of the drag behavior is given in the comments
The above callback works when Mainactivity calls Viewdraghelper's Setcallback method. When you click item on the Program list page (the first one that displays the ListView), The PlayVideo () method is called, and the facet is displayed internally through the Dragvideoview.show method, and the Dragvideoview is started. Then the video starts to play and we can drag and drop it.
This article is derived from the countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/53638896
So in the process of dragging, we want to rewrite the Ontouchevent method in Dragvideoview, as follows
The above method Finally, we call, Mdraghelper.processtouchevent (event), that is, our custom Customviewdraghelper class, this method does not change, Is the Processtouchevent method of Viewdraghelper.
This article is derived from the countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/53638896
Summarize this method
The Action_down, Action_move, and action_up events are handled 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 coordinates of the view are changed, call the Onviewpositionchanged method in the callback interface, layout The view according to the coordinate information, through Viewhelper Setscalex in this class, The Setscaley method is used to achieve the corresponding scaling of the view at the XY coordinates during the dragging process;
- 3. After action_up calls the Onviewreleased method in the callback interface, one of the important tasks in this method is to implement the automatic sliding of the view after the Action_up event. This is mainly using the Smoothslideviewto method in Viewdraghelper
Then arrive at the Forcesettlecapturedviewat method
Above start the viewdraghelper in the Mscroller, in the sliding process, by overriding the Computescroll method, can be used viewcompat.postinvalidateonanimation (this) Method Redraw View
Finally, due to the textureview of the display video during the drag-and-drop process, the Textureview.surfacetexturelistener can be set to monitor the current textureview changes.
The first time to get blog update reminders, as well as more Android dry, source code Analysis , Welcome to follow my public number, sweep the bottom QR code or long press to identify two-dimensional code, you can pay attention to.
If you feel good, easy to praise, but also to the author's affirmation, can also share this public number to you more people, original not easy
Dragvideo, a scheme that you can drag and drop when playing a video