Forum Xamarin.Android

Play 4 video together causes the system to reboot.

I wrote an application that continuously plays 4 video in 4 VideoView in the same activity.
The application works well , but sometimes the system reboots or freezes .
There seems no obvious memory problems .
Someone can give me an explanation ?

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;

        videoView1 = FindViewById<VideoView>(Resource.Id.videoView);
        videoView1.SetVideoPath(path + "/Download/a.mp4");
        videoView1.SetMediaController(new MediaController(this));
        videoView1.RequestFocus();

        videoView2 = FindViewById<VideoView>(Resource.Id.videoView2);
        videoView2.SetVideoPath(path + "/Download/b.mp4");
        videoView2.SetMediaController(new MediaController(this));
        videoView2.RequestFocus();

        videoView3 = FindViewById<VideoView>(Resource.Id.videoView3);
        videoView3.SetVideoPath(path + "/Download/c.mp4");
        videoView3.SetMediaController(new MediaController(this));
        videoView3.RequestFocus();

        videoView4 = FindViewById<VideoView>(Resource.Id.videoView4);
        videoView4.SetVideoPath(path + "/Download/d.mp4");
        videoView4.SetMediaController(new MediaController(this));
        videoView4.RequestFocus();

        StartVideos();
    }

    private void StartVideos()
    {
        t = new Thread(new ThreadStart(RunT));
        t.Start();

        t1 = new Thread(new ThreadStart(RunT1));
        t1.Start();

        t2 = new Thread(new ThreadStart(RunT2));
        t2.Start();

        t3 = new Thread(new ThreadStart(RunT3));
        t3.Start();
    }

  void RunT()
    {
        Process.SetThreadPriority(Android.OS.ThreadPriority.Display);

        for (; ; )
        {
            if (videoView1.IsPlaying == false)
            {
                videoView1.Start();
            }
        }
    }

    void RunT1()
    {
        Process.SetThreadPriority(Android.OS.ThreadPriority.Display);

        for (; ; )
        {
            if (videoView2.IsPlaying == false)
            {
                videoView2.Start();
            }
        }
    }

    void RunT2()
    {
        Process.SetThreadPriority(Android.OS.ThreadPriority.Display);


        for (; ; )
        {
            if (videoView3.IsPlaying == false)
            {
                videoView3.Start();
            }
        }
    }

    void RunT3()
    {
        Process.SetThreadPriority(Android.OS.ThreadPriority.Display);


        for (; ; )
        {
            if (videoView4.IsPlaying == false)
            {
                videoView4.Start();
            }
        }
    }
Sign In or Register to comment.