PowerShell
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebVideo
{ [DefaultProperty("FilePath")]
[ToolboxData("<{0}:WVC runat=server></{0}:WVC>")]
C#
public class WVC : WebControl
{
#region Declarations
private string mFilePath;
private bool mShowStatusBar;
private bool mShowControls;
private bool mShowPositionControls;
private bool mShowTracker;
#endregion
#region Properties[Category("File URL")]
[Browsable(true)]
[Description("Set path to source file.")]
[Editor(typeof(System.Web.UI.Design.UrlEditor),
typeof(System.Drawing.Design.UITypeEditor))]
C#
public string FilePath
{
get
{
return mFilePath;
}
set
{
if (value == string.Empty)
{
mFilePath = string.Empty;
}
else
{
int tilde = -1;
tilde = value.IndexOf('~');
if (tilde != -1)
{
mFilePath = value.Substring((tilde + 2)).Trim();
}
else
{
mFilePath = value;
}
}
}} // end FilePath property
[Category("Media Player")]
[Browsable(true)]
[Description("Show or hide the tracker.")]
Code
public bool ShowTracker
{
get
{
return mShowTracker;
}
set
{
mShowTracker = value;
}
}[Category("Media Player")]
[Browsable(true)]
[Description("Show or hide the position controls.")]
Code
public bool ShowPositionControls
{
get
{
return mShowPositionControls;
}
set
{
mShowPositionControls = value;
}
}[Category("Media Player")]
[Browsable(true)]
[Description("Show or hide the controls.")]
Code
public bool ShowControls
{
get
{
return mShowControls;
}
set
{
mShowControls = value;
}
}[Category("Media Player")]
[Browsable(true)]
[Description("Show or hide the status bar.")]
C#
public bool ShowStatusBar
{
get
{
return mShowStatusBar;
}
set
{
mShowStatusBar = value;
}
}
#endregion
#region "Rendering"
protected override void RenderContents(HtmlTextWriter writer)
{
try
{
StringBuilder sb = new StringBuilder(); sb.Append("<object classid=clsid:22D6F312-B0F6-11D0-94AB-
0080C74C7E95 ");
sb.Append("codebase=http://activex.microsoft.com/activex/
controls/mplayer/en/nsmp2inf.cab#Version=
5,1,52,701 Width = " + Width.Value.ToString() + " Height = "
+ Height.Value.ToString() + "type=application/x-oleobject
Code
align=absmiddle");
sb.Append("standby='Loading Microsoft+reg; Windows+reg; Media
Player components...' id=mp1 /> ");
sb.Append("<param name=FileName value=" + FilePath.ToString()
+ "> "); sb.Append("<param name=ShowStatusBar value=" +
ShowStatusBar.ToString() + "> ");
sb.Append("<param name=ShowPositionControls value=" +
ShowPositionControls.ToString() + "> ");
sb.Append("<param name=ShowTracker value=" +
Code
ShowTracker.ToString() + "> ");
sb.Append("<param name=ShowControls value=" +
ShowControls.ToString() + "> ");
sb.Append("<embed src=" + FilePath.ToString() + " "); sb.Append("pluginspage=http://www.microsoft.com/
Bash
Windows/MediaPlayer type=application/x-mplayer2 ");
sb.Append("Width = " + Width.Value.ToString() + " ");
sb.Append("Height = " + Height.Value.ToString());
sb.Append(" /></embed></object>");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(sb.ToString());
writer.RenderEndTag();
}
catch
{
// with no properties set, this will render "Display PDF
// Control" in a
// a box on the page
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write("Display WVC Control");
writer.RenderEndTag(); } // end try-catch
} // end RenderContents
#endregion
Grace Jamie4 pointsPosted Mar 11, 2015, 1:29 AM EDT
In general, MP4 and MOV files are ISO formats that require ISO Demux and MPEG4 or H.264 decoders (depending on the compression of the video file) to be installed on your machine.
If you can playback the same video files correctly using Windows Media Player on the same machine, this means the problem is most likely related to your code.
I think it's better to provide more details about the problem you have, because I don't think the code alone is enough in your case.
I am using a programming toolkit (leadtools) in my project to support playing MP4 (ISO) media files. I found the following threads that might help you:
http://www.c-sharpcorner.com/forums/thread/283196/video-format-or-mime-type-is-not-supported.aspx
http://www.c-sharpcorner.com/forums/thread/275853/video-player-for-the-avi3gpmp3mp4flv-file.aspx