0

trying to save 400 MB or more large video, while convert memory stream to Bytearray then the app shows a black screen and get terminated. cant able catches the exception even though try-catch placed inside the code. how to catch the exception and resolves the issue.

   public Byte[] StreamToByteArray(Stream stream)
    {
        try
        {
            byte[] bytes = new byte[16384];
            using (MemoryStream ms = new MemoryStream())
            {
                int count = 0;
                while ((count = stream.Read(bytes, 0, bytes.Length)) > 0)
                {
                    ms.Write(bytes, 0, count);
                }
                return ms.ToArray();
            }
        }
        catch (Exception Ex)
        {
            return null;
        }
    }

output window message

Explicit concurrent copying GC freed 12(31KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 1902KB/3MB, paused 168us total 57.118ms 02-19 14:52:46.566 D/Mono ( 2628): GC_TAR_BRIDGE bridges 83 objects 88 opaque 6 colors 83 colors-bridged 83 colors-visible 83 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.18ms tarjan 0.19ms scc-setup 0.18ms gather-xref 0.01ms xref-setup 0.00ms cleanup 0.07ms 02-19 14:52:46.566 D/Mono ( 2628): GC_BRIDGE: Complete, was running for 60.96ms 02-19 14:52:46.566 D/Mono ( 2628): GC_MAJOR_CONCURRENT_FINISH: (finishing) time 15962.01ms, stw 172.92ms los size: 1573896K in use: 1573042K 02-19 14:52:46.566 D/Mono ( 2628): GC_MAJOR_SWEEP: major size: 1936K in use: 972K [HotReload] (2021-02-19 14:52:40.9): INFO: (Sample.Android) Stopped Hot Reload session due to ExplicitlyEnded ...

Dev
  • 315
  • 2
  • 16
  • The max size of `bytes` is 16MB . Try to increase its size . – Lucas Zhang Feb 19 '21 at 11:25
  • if we choose the large video even though the size is set as 16MB it is prevent from crashing but the white screen came for a long time. any idea to catch the exception or prevent from showing whitescreen . – Dev Feb 22 '21 at 05:32
  • Check https://stackoverflow.com/questions/1594111/how-to-convert-video-to-byte-array-in-c . – Lucas Zhang Feb 26 '21 at 09:20

0 Answers0