Xamarin.android Xamarin Android视频播放器中的向前和向后选项存在问题

Xamarin.android Xamarin Android视频播放器中的向前和向后选项存在问题,xamarin.android,android-videoview,Xamarin.android,Android Videoview,我需要在Xamarin(Andriod)开发的移动应用程序中显示视频,其中向前移动15秒,向后移动5秒 在这方面我能得到一些帮助吗?在您的情况下,您似乎使用了MediaController。但是,如果您想自定义前进和后退的长度,则需要创建一个自定义的MediaController 在XML中 protectedoverride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin

我需要在Xamarin(Andriod)开发的移动应用程序中显示视频,其中向前移动15秒,向后移动5秒


在这方面我能得到一些帮助吗?

在您的情况下,您似乎使用了
MediaController
。但是,如果您想自定义前进和后退的长度,则需要创建一个自定义的
MediaController

在XML中
protectedoverride void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(这个,savedInstanceState);
SetContentView(Resource.Layout.activity_main);
//...
videoView=findviewbyd(Resource.Id.videoView1);
videoView.SetVideoURI(Android.Net.Uri.Parse(“xxx.mp4”);//保存的视频文件的路径。
videoView.Start();
按钮后退=FindViewById(Resource.Id.back);
后退。单击+=后退\u单击;
按钮播放=findviewbyd(Resource.Id.play);
播放。单击+=播放\单击;
按钮前进=FindViewById(Resource.Id.forward);
向前。点击+=向前点击;
}
私有无效转发\u单击(对象发送方,事件参数e)
{
videoView.SeekTo(videoView.CurrentPosition+5*1000);
}
私有无效播放\单击(对象发送者,事件参数e)
{
var按钮=发送方为按钮;
if(videoView.IsPlaying)
{
button.Text=“播放”;
videoView.Pause();
}
其他的
{
button.Text=“暂停”;
videoView.Start();
}
}
私有无效返回\u单击(对象发送方,事件参数e)
{
videoView.SeekTo(videoView.CurrentPosition-15*1000);
}
通过这种方式,您只需根据需要设置按钮的图标

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    android:orientation="vertical">

    <VideoView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/videoView1" />

    <LinearLayout
        android:background="@android:color/darker_gray"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <Button
            android:text="back"
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>

        <Button
            android:text="play"
            android:id="@+id/play"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>

        <Button
            android:text="forward"
            android:id="@+id/forward"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>

    </LinearLayout>



</LinearLayout>

VideoView videoView;

   protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        SetContentView(Resource.Layout.activity_main);

       //...


        videoView = FindViewById<VideoView>(Resource.Id.videoView1);
        videoView.SetVideoURI(Android.Net.Uri.Parse("xxx.mp4")); // Path of your saved video file.

        videoView.Start();


        Button back = FindViewById<Button>(Resource.Id.back);
        back.Click += Back_Click;

        Button play = FindViewById<Button>(Resource.Id.play);
        play.Click += Play_Click;

        Button forward = FindViewById<Button>(Resource.Id.forward);
        forward.Click += Forward_Click; ;
    }

    private void Forward_Click(object sender, EventArgs e)
    {
        videoView.SeekTo(videoView.CurrentPosition + 5 * 1000);
    }

    private void Play_Click(object sender, EventArgs e)
    {
        var button = sender as Button;
        if (videoView.IsPlaying)
        {
            button.Text = "Play";
            videoView.Pause();

        }
        else
        {
            button.Text = "Pause";
            videoView.Start();
        }

    }

    private void Back_Click(object sender, EventArgs e)
    {
        videoView.SeekTo(videoView.CurrentPosition-15*1000);
    }