В вашем файле xml layout
вы найдете что-то вроде
<com.google.android.youtube.player.YouTubePlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ytPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</com.google.android.youtube.player.YouTubePlayerView>
Оберните его другим пользовательским ViewGroup
, например,
<!--
Make sure to prepend the complete package of the `CustomViewGroup`.
-->
<CustomViewGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.google.android.youtube.player.YouTubePlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ytPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</com.google.android.youtube.player.YouTubePlayerView>
</CustomViewGroup>
Определите ваш CustomViewGroup
public class CustomViewGroup extends ViewGroup {
private boolean actionDownReceived = false;
private final int DELTA_TOLERANCE = 70;
private int actionDownX = -1;
private int actionDownY = -1;
public CustomViewGroup(Context context)
{
}
public CustomViewGroup(Context context, AttributeSet attrSet)
{
}
public CustomViewGroup(Context context, AttributeSet attrSet, int defStyleAttr)
{
}
// Now write the appropriate methods to capture touch events.
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
switch (event.getActionMasked())
{
case MotoinEvent.ACTION_DOWN:
actionDownReceived = true;
actionDownX = event.getRawX();
actionDownY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
// Check if user moved his finger, there should also be a time check, i.e. if user pressed longer for a click. But I'll let you come up with it.
if (Math.abs(event.getRawX() - actionDownX) >= DELTA_TOLERANCE) {
actionDownReceived = false;
}
else if (Math.abs(event.getRawY() - actionDownY) >= DELTA_TOLERANCE) {
actionDownReceived = false;
}
break;
case MotionEvent.ACTION_UP:
if (actionDownReceived) {
if (isPressOnLeftSide(event.getRawX(), event.getRawY()) {
// Your logic for rewind.
}
else if (isPressOnRight(event.getRawX(), event.getRawY()) {
// Your logic for forward.
}
actionDownReceived = false;
}
break;
case MotionEven.ACTION_CANCEL: {
actionDownReceived = false;
break;
}
}
super.dispatchTouchEvent();
}
}
Я не проверял код, выполняя его, поэтому могут быть синтаксические ошибки и ошибки компилятора, но, как вы просили о базовой реализации, это должно сработать.