Sina Eizad

Hi

im trying to play a video which is loaded from an embedded resource into a stream. in MCI's documentation it says that:

"MCI can open AVI files by using a file-interface pointer or a stream-interface pointer. To open a file by using either type of interface pointer, specify an at sign (@) followed by the interface pointer in place of the file or device name for the lpszDevice parameter."

im coding in C#

if i have a stream like this
Stream st

which holds the video, then how do i get the stream interface pointer or what would the open string which is to be send using mcisendstring look like

"open @" + &st wont work because you can't get the address of a managed type being the System.IO.Stream

any help would be appreciated

thanks



Re: Visual C# General using MCI to play video stream

Citizen on the earth

Hi Sina,

Based on my understanding to MCI playing vedio, I think you can try to declare mcisendstring in C# as follows:

Code Snippet

using System;
using System.Runtime.InteropServices;

[DllImport("winmm.dll")]
extern static int mciSendString(string command, IntPtr responseBuffer,int bufferLength, int nothing);

Then call mcisendstring as the following sample codes:

Code Snippet

Console.WriteLine("Type in the fully qualified path to the file you want to play");
string file = Console.ReadLine();

string command = string.Format("play {0}",file);
IntPtr response = Marshal.AllocHGlobal(128);
int err = mciSendString(command,response,128,0);

Try to check out this article for more details - http://www.codeproject.com/audio/moemeka7.asp df=100&forumid=33405&exp=0&select=1225074

Hope this helps,

Regards,

Citizens on the earth





Re: Visual C# General using MCI to play video stream

Sina Eizad

thanks you for your reply

thanks for the code it did help but there is still a problem. as i mentioned in my original post my projet requires me to load the .wmv video which is embedded into a resource DLL. i need a way to play the video without having to write it into a file and then passing the address of the file to mci.

im sure people must have come across this situation before where they have their videos as embedded resources and want to play them from some sort of stream like byte stream or memory stream. my understanding was that mci could do this task for me by passing a stream interface pointer as microsoft says in msdn(mentioned in original post).

however if there is a better way to do this even using a different technology(other than mci) i am open to suggestions.

thanks again






Re: Visual C# General using MCI to play video stream

Citizen on the earth

Hi Sina,

Thanks for your quick reply.

If you would like to load the .wmv from a embeded resource DLL, based on my understanding, MCI can't play the vedio stream directly, and you can try to write it as a file to play using MCI. Here are some sample codes for your reference:

Code Snippet

int bufferSize = 4096; // use a buffer of 4KB

byte[] buffer = new byte[bufferSize];
using(Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream("Namespace.file.ext"))
using(Stream output = new FileStream("file.ext", FileMode.Create))
{
int byteCount = input.Read(buffer, 0, bufferSize);
while(byteCount > 0)
{
output.Write(buffer, 0, byteCount);
byteCount = input.Read(buffer, 0, bufferSize);
}
}

The original Thread about "Embedded Resources" is from http://channel9.msdn.com/ShowPost.aspx PostID=269027

Hope this helps,

Regards,

Citizens on the earth