我正在尝试编写一个应用程序,在xamarin应用程序中无限循环视频。
我使用Odroid-X4 U作为设备连接到电视,使“SaverScreen”播放视频.
下面是我的代码:
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();
}
此代码是功能,但几个小时后视频完全冻结,我必须重新启动我的设备完全重新启动视频。
我还放了一小块代码来检查RAM,这不是存储问题
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;
});
}
有没有人有一个解决方案,使视频不冻结后一段时间?
我还去了设备日志(logcat),没有显示任何关于视频错误的信息。
1条答案
按热度按时间h79rfbju1#
根据原生android关于Seamless video Loop with VideoView的案例,你可以尝试用
videoView.setOnPreparedListener
方法循环视频。首先,声明自定义监听器类:
然后为videoview设置监听器: