LibVLCSharp - Play file from zip archive

47 views Asked by At

I'm trying to improve some of my already-existing app in WinForms, that uses libvlcsharp to play locally storaged files. I need to add support for playing file (usually h264 mp4) inside zip. I can handle it, if i use MemoryStream in the middle - to cache in-zip file content:

static public Stream StreamFromZipFile(string archivePath, string filePath)
{
            ZipArchive zipArchive = ZipFile.OpenRead(archivePath);
            foreach (ZipArchiveEntry zipArchiveEntry in zipArchive.Entries)
            {
                if (zipArchiveEntry.FullName.Equals(filePath, StringComparison.OrdinalIgnoreCase))
                {
                    return zipArchiveEntry.Open();
                }
            }
            throw new FileNotFoundException("No " + filePath + " in " + archivePath);
        }


Stream inFileStream;
Stream memoryStream = new MemoryStream();
inFileStream = StreamFromZipFile(filePath, inFileName);
inFileStream.CopyTo(memoryStream);
media = new LibVLCSharp.Shared.Media(LibvlcHandlerMain.libVLC, new StreamMediaInput(memoryStream));
_vlcMediaPlayer.Play(media);

if I use new StreamMediaInput(inFileStream) instead, I get random results (in most cases - error, sometimes it plays by accident ;)) I can guess it's some race condition - libvlcsharp reads unfinished (or empty) file. Can I somehow skip caching whole file in memory?

1

There are 1 answers

1
BartekC On

It was buggy zip implementation - works fine after switching to DotNetZip