Click here to Skip to main content
15,443,631 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a video file like this:

C#
FileStream streamWriter = File.Create(fullPath);
                    int size = 2048;
                    byte[] data = new byte[2048];
                    while (true)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            streamWriter.Write(data, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }
                    streamWriter.Close();

What I need to do here is that I want to play the video from memory stream (axwindowsmediaplayer).

Lots of people have this problem. Can anyone help me please?
Thanks in advance!

[Edited]Code is Wrapped in "pre" tags[/Edited]
Posted
Updated 25-Feb-22 3:19am
v4

Hi,
I'm not sure you can play video from memory stream using axwindowsmediaplayer and why you should read file to memory at first and then play it?
Just use URL property described here:
http://msdn.microsoft.com/en-us/library/dd562470%28v=vs.85%29.aspx[^]

But if you need to play video from memory for some reason then I think you need to use DirectShow.

For DirectShow I'm researching this problem too...I found the following old topic on DirectShowNet forum:
http://sourceforge.net/projects/directshownet/forums/forum/460697/topic/1777460[^]

Probably GSSF filter should help to solve this. It can be downloaded with samples of DirectShowNet:
http://sourceforge.net/projects/directshownet/files/DirectShowSamples/2010-February/[^]
Samples\Misc\GSSF

I hope this will help.

--
Timur
 
Share this answer
 
Comments
tulasiram3975 25-Jan-11 0:04am    
in order to reduce time i need to play from memory stream
TimGameDev 25-Jan-11 4:44am    
Could you elaborate what time do you want to reduce?
tulasiram3975 25-Jan-11 5:45am    
actually am unzip a video file from .zip file it takes long time to extracting the file at specified location after that i am playing the unzipped file the entire process take long time so that i need to reduce the time that's why i need to play from memory stream
TimGameDev 26-Jan-11 7:59am     CRLF
From my point of view if you are working at serious program you should use DirectShow to play video. For example: Kantaris is open source (C#) player can plays video files from archive: http://sourceforge.net/projects/kantaris/ In case if you are creating simple program just unzip file and play it using axwindowsmediaplayer.
tulasiram3975 28-Jan-11 3:27am    
sir could you please give me the directions to play video using DirectShow i have seen DirectShow library but i don't know how to use(i am seriously doing sir) please help me. you only the person helps me kindly help me thank you
Hi mate,
Impossible is what I hate most
So there a bit ugly solution but works actually, which goes:
stream the media file stream by TCP and receiving it after this by your embedded player
C#
/* a listener function, when a client connects, it starts streaming the obj stream.
the parameter is of type object here, so I can call this function as a delegate when starting the thread. */

        void HTTPStreamer(object obj)
        {
            Thread.Sleep(1000);
            Stream Reciever = (Stream)obj;
            TcpListener listener = new TcpListener(IPAddress.Loopback, 12);
            listener.Start();
            TcpClient client = listener.AcceptTcpClient();
            client.Client.Send(Encoding.Default.GetBytes("HTTP/1.1 200 OK\nDate: Tue, 02 Aug 2011 22:24:05 GMT\nServer: Apache/2.2.8 (Win32) PHP/5.2.5\nLast-Modified: Tue, 02 Aug 2011 22:21:13 GMT\nETag: \"1000000009896-1743f-4a98d2a63ee22\"\nAccept-Ranges: bytes\nContent-Length: 95295\nKeep-Alive: timeout=5, max=100\nConnection: Keep-Alive\nContent-Type: text/plain"));// HTTP Headers
            int length = 0;
            byte[] buffer = new byte[1024];

            while (Reciever.CanRead)
            {
                try
                {
                    length = Reciever.Read(buffer, 0, 1024);
                    client.GetStream().Write(buffer, 0, length);
                }
                catch
                {
                    break;
                }
            }

        }
MemoryStream YourStream
Thread th = new Thread(HTTPListener);
th.start(YourStream);

<pre>


My first solution in this lovely site, sorry for the mistakes
Cheers
 
Share this answer
 
v4
Comments
tulasiram3975 9-Apr-12 5:29am    
Have You Seen Tags for this question Its A windows app..
Member 14531531 1-Oct-19 0:44am    
This seems to be like one of the solution of the problem. can you please give some more details on this solution. If you can add a small sample program of it then it will be more handy. thanks in advance.
[no name] 25-Feb-22 2:49am    
Can we have an example/demo project ?
Dave Kreskowiak 25-Feb-22 12:58pm     CRLF
After 11 years, I don't think you're going to get a response.
[no name] 27-Feb-22 14:07pm    
Yes, you are right... but still asking is worth the effort. ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900