0

I'm trying to code an application that loops a video indefinitely in an xamarin application.

I'm using a Odroid-X4U as device to connect to a TV to make a "SaverScreen" that play videos.

Here my code :

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    session = new SessionManager(this);

    memoryTextView = FindViewById<TextView>(Resource.Id.textViewMemory);
    hourTextView = FindViewById<TextView>(Resource.Id.textViewHour);
    memoryTimer = new Timer(UpdateMemory, null, 0, 1000);

    videoView = FindViewById<VideoView>(Resource.Id.videoView1);
    videoView.Completion += VideoView_Completion;

    Window.AddFlags(WindowManagerFlags.Fullscreen);

    PlayNextVideo();
}

private void PlayNextVideo()
{
    string tmpPath = App.AppMainFolder + "/" + videoUrls[1];
    videoView.SetVideoPath(tmpPath);
    videoView.Start();
}

private void VideoView_Completion(object sender, EventArgs e)
{
    videoView.StopPlayback();
    videoView.Dispose();
    videoView = FindViewById<VideoView>(Resource.Id.videoView1);

    hourTextView.Text = DateTime.Now.ToString("HH:mm:ss");

    currentIndex = (currentIndex + 1) % videoUrls.Length;
    PlayNextVideo();
}

this code is functional, however after several hours the video freezes completely and I have to restart my device completely to restart the video.

I also put a little bloc of code to check the ram, and it's not a storage problem

private void UpdateMemory(object state)
{
    var memoryInfo = new ActivityManager.MemoryInfo();
    var activityManager = (ActivityManager)GetSystemService(ActivityService);
    activityManager.GetMemoryInfo(memoryInfo);

    RunOnUiThread(() =>
    {
        var currentTime = DateTime.Now.ToString("HH:mm:ss");
        memoryTextView.Text = "RAM : " + (memoryInfo.AvailMem / 1048576L) + "MB | time : " + currentTime;
    });
}

Does anyone have a solution so that the video doesn't freeze after a while?

I also went to the device logs (logcat) and nothing is displayed about the video bug.

Arnaud
  • 1
  • 2

1 Answers1

1

According to the native android case about Seamless video Loop with VideoView, you can try to loop the video with the videoView.setOnPreparedListener method.

First of all, declare the custom listener class:

public class MyListener : Java.Lang.Object, IOnPreparedListener
{
    public void OnPrepared(MediaPlayer mp)
    {
        mp.Looping = true;
    }
}

And then set the listener for the videoview:

videoView = FindViewById<VideoView>(Resource.Id.videoView1);
videoView.SetOnPreparedListener(new MyListener());
Rafael
  • 1,281
  • 2
  • 10
  • 35
Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • Hello, thank you. I'll come back to you tomorrow after testing it for 24 hours ! – Arnaud May 22 '23 at 07:29
  • You are welcome. Looking forward to your feedback. @Arnaud – Liyun Zhang - MSFT May 23 '23 at 01:43
  • Unfortunately, the video still freezes after a few hours. When I came back this morning, I didn't restart my device, only the application and the video were still frozen, so I'm checking the logs to see if there's something that was blocking the video, but i didn't find anything i'm not used to stackoverflow, i don't know where i can send you this logs – Arnaud May 23 '23 at 06:58
  • Did you keep the code you used earlier? In addition, is there any limit on the TV such as the power saving mode? @Arnaud – Liyun Zhang - MSFT May 23 '23 at 07:23
  • Yes i keep the code, and no there is no power saving mode, because these devices are already use in the factory where i work and there are turn on 24h/24h with no probleme – Arnaud May 23 '23 at 07:38
  • All right, please try to delete the code you used earlier(such as the `PlayNextVideo()` and `VideoView_Completion(object sender, EventArgs e)` ) and only used the code I provided. @Arnaud – Liyun Zhang - MSFT May 23 '23 at 07:41
  • for my test yesterday, I just use one time PlayNextVideo(), i delete the VideoView_Completion(object sender, EventArgs e). – Arnaud May 23 '23 at 07:51
  • Sorry for I have no idea about this. – Liyun Zhang - MSFT May 23 '23 at 08:18
  • no problem, thanks for your help. I'Il get back to you if a find a solution – Arnaud May 23 '23 at 08:22