Playing video files in C# Winforms - c#

I am learning C#, and have created an application with winforms that can play video files from my local hard drive. Here is my code for playing a file that is stored in the same directory as my exe file.
My question is - the actual file is still accessible to anyone that can access my exe folder, and therefore, can play the video file just by clicking on it. Is it possible to embed the video file in such a way that the actual video file remain inaccessible to someone I give my application to use? I mean he/she should only be able to use the exe file to access the application and then play the video using the application.
I have read this post here to get some idea: How to store a video file in exe file in c# and play it
However, this answer is also getting the physical file url, converting to bytes from resource and then using the url to play. Therefore, if I had to give my application to someone else I would still have to copy the physical file to a folder, and again it remains accessible for an open-by-click option.
I am a complete newbie on this, so advance thanks for helping me out.
{
string exepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
string vdopath = System.IO.Path.Combine(exepath, "MyFolder\\SecondFolder\\VideoFile.mkv");
axWindowsMediaPlayer1.stretchToFit = true;
axWindowsMediaPlayer1.URL = vdopath;
}```

It's possible to add any file to a project and from the Properties set the Build Action to "Embedded Resource", then to read the file this SO answer - https://stackoverflow.com/a/3314213/4000335

Related

How to save file in Downloads folder on iOS with Unity

I am currently facing a problem, where I need to save a file (PDF) into downloads folder on iPhone (or in the best scenario prompt a download somehow) from Unity.
We can save data in Application.persistentDataPath, but that is, to my knowledge, inaccessible from the device itself.
Do you have any ideas, it will be something with the File class, but I do not know which path to put in there.

C#: How to read a file that's in use by another process

There is one text file in hard drive which continuously writing by some application XYZ.
Now, from application ABC, I am trying to read the file, but I am getting error,
the process cannot access the file because it is being used by another process
Note - I don't have control over XYZ application, still is there any way to read the file from application ABC?
byte[] data = File.ReadAllBytes(File.FullName)
Access the file in read mode so that you will not get this error.
Try this solution
How do I open an already opened file with a .net StreamReader?

Where to store temporary files using a windows forms application

I have an application that downloads a file from FTP, reads the file, then deletes it (i download a temporary file because the stream gets disposed before i read the end of the data and i get an exception) and I was wondering what is the programming convention for storing temporary files? Basically right now I just download the file to the desktop directory (testing phase still) so it pops up on the desktop for a second while it's read then deleted.
Use System.IO.Path.GetTempFileName() to get a randomly named file in the system's temp directory. Download to there.
Be sure to use System.IO.File.Delete() when you're done with it!
https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=vs.110%29.aspx

Keep file restricted from opening it by anyone

I have an application in c#.net in which I have embeded the SWF file in SWFObject from COM Object.
Now after installation, the original SWF file also available in the application root directory. So from that place(application root directory) anyone can access that file. But I want to restrict that file from being opened.
axShockwaveFlash1.Movie = Directory.GetCurrentDirectory() + "\\XYZ.swf";
I did something like this.
So how can I restrict that file in application root directory such that only from my application I can access it..??
You can embed the file into a dll or exe file and play it from there. this way it is not (as a seperate file) in the file system at all.
For details see How to embed and access resources by using Visual C#.
You could save the swf file binary data as static bytes in your code and statically load them and convert back to an swf file. The conversion might take a little while but it only occurs once as you open the program.
Edit:
But k3b's answer is better.
Permissions are based on users, not applications, so the short answer is you can't. However, you can build your own application-specific authentication pretty easily. Have your SWF require specific FlashVars to be set in order to move beyond frame 1. People can still decompile your SWF but this will at least stop most people. Another option is to try to store the data within you binary somehow and load the SWF using a byte-array, see this post for one attempt at that.

Playing an MP4 in a zip file through a network location

I'm building a video system, and have came across a problem of accessing a video held in a remote location. Now predicament is that I don't want to mess around with the zip file by extracting the data, this would take too long from a user perspective and would rather be able to open video file directly from within side the zip. My question is, is this possible? The ability to open a file is not something I've found within the DotNetZip library.
The only solution I've found is pointing VideoLAN at the zip file and playing it from there. However, doing this programmatically is something I'm massively struggling with, through the VideoLan DotNet for WinForm & WPF C# plugin and it's lack of examples. Just wondering is there any alternative means?
Why dont you use the VLC ActiveX Directly ,just import the AxVlc.dll to you're project ,than you can select the VLC Plugin from Toolbox in VS (VLC Plugin v2 prefered).
Than you can do something vlc.playlist.add("FileName",Null,""); than use vlc.playlist.play(); version's under 0.9.9 works with Loop ,new version's you should build the Loop Function by you're self.
What's the reason of compressing video files? They are already compressed, and far better than zip can do.

Categories