Question

I want to add video file in my windows form application, the video format type is MP4. I already searched on how to add video and I found an answer to use windows media player library.

I used it but once I put the complete URL of my file, it works on my machine, but when I install it on any other, it does not play. I know the reason that I'm giving location of video which is my HD location, then I searched further and found embed resources, I do change build action into embed resources, but again having same problem.

How can I access my embed file within my code? I already tried the way like namespace.file.mp4 or namespace.properties.resources.file.mp4 but it says that:

Error 1 Cannot implicitly convert type 'byte[]' to 'string' L:\Project SciMult-calc\videotesting2\videotesting2\Form1.cs 29 41 videotesting2

Was it helpful?

Solution 2

this is my brief code i want to play a video when user click "About" menustripitem

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Resources;

namespace videotesting2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = @"L:\about.mp4";

        }
    }

}

OTHER TIPS

When you access the resource it is byte[] which is why you can't play the video. Your method wants a path not a byte[].

You can write the resource to disk then play it.

namespaces needed

using System.Reflection;
using System.IO;

Something like this

//Place it in the directory of your application
string mp4Path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mp4File.mp4");

//check if it hasn't been written to disk yet
if (!File.Exists(mp4Path))
{
    //write it to disk
    File.WriteAllBytes(mp4Path, namespace.properties.resources.file.mp4);
}

//play using mp4Path
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top