i have used "embed" tag for Flv file, Flash Player for "swf" file and "object tag for other files... everything working fine with IE but in Mozilla only swf files working properly.. can anybody s开发者_如何学编程uggest me right way to play video of any type in IE and Mozilla both
i did it using ffmpeg... finally i converted file nto .flv then created its thumbnail and played video using "embed" tag which works fine in IE and mozila both
here is my wcfservice file code
Interface file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfFileUploader
{
// NOTE: If you change the interface name "IFileUploader" here, you must also update the reference to "IFileUploader" in Web.config.
[ServiceContract]
public interface IFileUploader
{
[OperationContract(Action = "UploadFile", IsOneWay = true)]
void UploadFile(FileUploadMessage request);
}
[MessageContract]
public class FileUploadMessage
{
//[MessageHeader(MustUnderstand = true)]
//public DataContracts.DnvsDnvxSession DnvxSession;
//[MessageHeader(MustUnderstand = true)]
//public DataContracts.EApprovalContext Context;
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageHeader(MustUnderstand = true)]
public string ThumbnailName;
[MessageHeader(MustUnderstand = true)]
public string ffmpegPath;
[MessageBodyMember(Order = 1)]
public System.IO.Stream FileByteStream;
}
}
Service.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.IO;
using System.Web;
using System.ServiceModel.Activation;
using System.Diagnostics;
namespace WcfFileUploader
{
// NOTE: If you change the class name "FileUploader" here, you must also update the reference to "FileUploader" in Web.config.
//[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class FileUploader : IFileUploader
{
//public FileUploader()
//{
// HttpContext httpContext = HttpContext.Current;
// if (httpContext != null)
// {
// httpContext.Response.BufferOutput = false;
// }
//}
public void UploadFile(FileUploadMessage request)
{
try
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;
//string uploadFolder = @"C:\TEMP\";
//string filename = request.FileName;
string filePath = request.FileName;//Path.Combine(uploadFolder, filename);
using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
//read from the input stream in 4K chunks
//and save to output stream
const int bufferLen = 4096;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
string outputfilename = ConvertToFlash(request.FileName, request.ffmpegPath);
CreateThumbnail(outputfilename, request.ffmpegPath, request.ThumbnailName);
}
catch (Exception ex)
{
}
}
private string ConvertToFlash(string inputfile, string ffmpegPath)
{
string outputfile, filargs;
outputfile = inputfile.Replace(Path.GetExtension(inputfile).ToString(), ".flv");
filargs = "-i \"" + inputfile + "\" -ar 22050 \"" + outputfile + "\"";
Process proc;
proc = new Process();
proc.StartInfo.FileName = ffmpegPath;
proc.StartInfo.Arguments = filargs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = true;
try
{
proc.Start();
}
catch (Exception)
{
}
proc.WaitForExit();
proc.Close();
File.Delete(inputfile);
return outputfile;
}
private void CreateThumbnail(string outputfile, string ffmpegPath, string ThumbnailPath)
{
string thumbargs;
thumbargs = "-i \"" + outputfile + "\" -vcodec png -vframes 1 -an -f rawvideo -s 320×240 \"" + ThumbnailPath + "\"";
Process thumbproc = new Process();
thumbproc = new Process();
thumbproc.StartInfo.FileName = ffmpegPath;
thumbproc.StartInfo.Arguments = thumbargs;
thumbproc.StartInfo.UseShellExecute = false;
thumbproc.StartInfo.CreateNoWindow = false;
thumbproc.StartInfo.RedirectStandardOutput = true;
try
{
thumbproc.Start();
}
catch (Exception)
{
}
thumbproc.WaitForExit();
thumbproc.Close();
}
}
}
this code uploads file converts it into .flv and creates thumbnail for the same
here is web.config for this Service
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<httpRuntime maxRequestLength="65536"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="FileTransferServicesBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" messageEncoding="Mtom"
maxBufferSize="65536" maxReceivedMessageSize="67108864">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfFileUploader.FileUploaderBehavior" name="WcfFileUploader.FileUploader">
<endpoint address="" binding="basicHttpBinding" contract="WcfFileUploader.IFileUploader" bindingConfiguration="FileTransferServicesBinding">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfFileUploader.FileUploaderBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
web.config... service end point in website
<system.serviceModel>
<bindings>
<basicHttpBinding>
<!-- buffer: 64KB; max size: 64MB -->
<binding name="FileTransferServicesBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://servername/WcfFileUploader/FileUploader.svc" binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding" contract="IFileUploader" name="BasicHttpBinding_IFileUploader"/>
</client>
</system.serviceModel>
<system.web>
<httpRuntime maxRequestLength="65536"/>
</system.web>
Embed tag used to play video...
<embed src="player.swf" height="425px" width="425px" allowscriptaccess="always" allowfullscreen="true" flashvars="file=../Videos/b28f9741-6dd5-4584-b2b9-cb6626e4aa33.flv" />
Have a look into SWF object - http://code.google.com/p/swfobject/
"SWFObject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file"
精彩评论