问题
I trying to load my video from the resources folder but its not playing automatically once my form load. Can I know what mistake i have done. Thank you.
This is my c# code:
private void Form2_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = @"Resources/abc.mp4";
axWindowsMediaPlayer1.Ctlcontrols.play();
}
回答1:
Well I have solved it my ownself. Actually, I accidentally added the @ symbol into my url. That causes the problem. This is the updated code.
private void Form2_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = "Resources\\abc.mp4";
axWindowsMediaPlayer1.Ctlcontrols.play();
}
回答2:
To do that king of thing, you must get the stream of your resource. So that code should work for you because works for me :)
// temporary file path - your temp file = video.avi
var strTempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Video.avi");
try
{
// ResourceName = the resource you want to play
File.WriteAllBytes(strTempFile, Properties.Resources.ResourceName);
axWMP.URL = strTempFile;
axWMP.Ctlcontrols.play();
}
catch (Exception ex)
{
// Manage me
}
You can implement a axWMP_PlayStateChange method to remove video.Avi at the end.
Hope it could help you
来源:https://stackoverflow.com/questions/32094176/c-sharp-load-video-from-resources-folder-not-playing