|
Im not trying to connect a webcam, but to play a movie.
private VideoComponent movie;
movie = new VideoComponent(this, "Content\\Video\\splash");
and
Components.Add(this.movie);
Hope you can help me
|
|
|
|
|
Hi Jan;
The constructor expects the extension (.avi, .mpeg, .wmv) to be present in the videoFile string, since it has to handle the file differently depending upon which type of format is being used. For example:
movie = new VideoComponent(this,@"Content/Video/splash.avi");
Also, make sure the path is relative to the directory where the executable for the application is running.
|
|
|
|
|
Hi Jan;
The exception that you refer to is thrown by the Constructor for the VideoTexture class, caught in the VideoComponent class, and rethrown for the application to handle. The message that you are getting is from the VideoComponent class, but there will be more information about the specific reason for the exception in the InnerException. For many (but not all) of the possible reasons for failure there may also be console messages that are generated, so you might want to watch for those. For example, there will be console messages if the program is unable to enumerate a camera on your system (if you are trying live video), if it is being asked to play a video file format that is not supported, if it is unable to create the DirectShow Filter Graph for some reason, or if there is some other error while trying to use a DirectShow method. If checking out the inner exception doesn't answer your question, please let me know.
|
|
|
|
|
Ive checked all (solution explorer, release directory and everything seems to be fine. I stil get this:
An unhandled exception of type 'System.Exception' occurred in xnaVideoLibrary.dll
Additional information: Unable to Load Webcam Component.
I have:
movie = new VideoComponent(this, @"Content\\Video\\splash.wmv");
Components.Add(this.movie);
which error is caused by.
Any ideas?
|
|
|
|
|
You are using the string literal (@) and escaped characters \\ in the same string.
Try:
movie = new VideoComponent(this,@"Content\Video\splash.wmv");
Also, just to confirm, are you sure that you have your "Content" directory under your \xnaVideoViewer\bin\x86\Release directory like this:
\xnaVideoViewer\bin\x86\Release\Content\Video\splash.wmv
Just to make sure the program can find your .wmv file, you could use an absolute address string like this:
"C:\Code\XnaVideo\\xnaVideoProjectFiles\xnaVideoViewer\bin\x86\Release\Content\Video\splash.wmv" for your videoFile parameter.
Also, as a test, you could put your splash.wmv file in your release directory, and use:
movie = new VideoComponent(this,"splash.wmv");
If that does not work then we might have to dig deeper, and see what the inner exception says...
|
|
|
|
|
1. Thanks - now I know what @ does (I added it before posting that message. I always use \\.
The problem was found by myself - lOl.
I had a problem with Initialise method, but I solved the problem and now It works fine.
Thanks for help anyway
|
|
|
|
|
Will this work on Xbox360 too?
|
|
|
|
|
I have not tested the class on the XBox 360 (Since I don't own one...), but it would be interesting to try it. It does use the "Third-Party" DirectShowLib-2005.dll, which may be a problem (or not, since it is Managed code). Anyway, there is no harm in giving it a try! Please let me know how you make out, if you do decide to experiment.
|
|
|
|
|
I dont own Xbox360 too, and thats why I'm asking.
|
|
|
|
|
Thanks for sharing this. This will definitely help with some future projects I have planned.
|
|
|
|
|
Gr8 article.
Can anyone provide me url where to find sourcecode for compressing and uncompressing video frame with H.264 algorithm.
Thank you.
|
|
|
|
|
|
Due to popular demand I have extended the VideoTexture class to now consume .avi, .mpeg, .wmv video clips as well as live video. This update has been sent to CodeProject today (30 July 2007), and should be available in a couple of days. Thanks to alexreg for his assistance and encouragement.
|
|
|
|
|
Great job with this... it seems to be working for me (although it actually displays from my TV tuner, since I don't have a web cam), and the code is well structured and documented. I'm be really keen to see if you'll produce a version of this that renders AVIs/MPEGs. This is something I'm desperate to include in my XNA game. Perhaps I'll play around with it, and let you know if I get it to play back video.
|
|
|
|
|
Thanks for your comments. I have had several people ask me about extending the class to play AVI's or MPEG files. This should be quite doable, and perhaps I will take a look at the problem this weekend. Cheers!
|
|
|
|
|
Sounds great... and just let us know please if you'd like us to put any notice/license in the game, apart from the DirectShow.NET one.
|
|
|
|
|
I have taken a look at adding support for playing video files as textures this morning, and I have something working fairly well. I am in the process of refactoring it to accomodate the additional complexities of starting, pausing, looping, positioning, controlling playback rates, and so on within the VideoTexture class itself - things that were not really needed for live video. Also, I am trying to work through the problem of handling DirectShow graph events without using a windows control in the class; it is a bit tricky, and a bit ugly, to manually use the MediaEvent.GetEventHandle() method with a kernel32.dll pInvoke to WaitForSingleObject, but I have not been able to figure out anything clean for it... It will take a few days (from today) to update this CodeProject page; Send me an email if you are keen to get the work-in-progress (StephenBognerATshawDOTnet) and I will send you what I have.
As far as notice/license goes, all this stuff is Open Source or Public Domain; so use it as you see fit, at your own risk. As far as credit goes, none is required. I could not do any of this programming without the generosity of others showing me how over the years; I am just trying to give back a little bit.
Cheers!
|
|
|
|
|
Great to hear you've made progress so quickly. I'll be thanking you hugely when I get this in my game! I should be able to wait a few days, as this isn't integral to the immediate development of what I'm personally working on, albeit something very useful. If it ends up taking longer, that's not a problem of course, but I may just get curious enough to see the in-progress code... Also, I originally tried to write something like this myself, and I felt the same way about being forced to use the Windows message loop and a control to receive event feedback. I'd thought that I'd actually found another solution to it, in fact. I'll send you an email letting telling you about it (if I can dig it out from my old project or wherever it was).
(P.S. I'll be more than happy to credit you for this, so just let me know if you don't want your name to appear - that's really a side point for the moment though...)
|
|
|
|
|
File playback is now working, with the following issues:
1. The playback rate seems to be too fast, and I have not been able to control the speed of playback using MediaSeeking.SetRate() or MediaPositions.put_Rate() because these methods are apparently not implimented in DirectShow.NET (at least that is the exception that is raised). Maybe I will have to write my own method to step through frames at a known rate... This is probably a good idea for a class that will be used for a VideoTexture anyway, since it is very likely that users will want to control the rate at which the texure flows over the geometry anyway.
2. I have implimented event capture using MediaEventEx.GetEventHandle() and Kernel32.WaitForSingleObject(), but it only captures the first event (ClockChanged), and does not want to reset and send additional events (like Completed, which I am watching for to enable looping). I will have to hit the net to see what I am doing wrong...
3. As an alternate approach, I set up a timer to call my HandleGraphEvents method at regular intervals. Not as efficient as only calling it when events are raised (like in 2), but I don't need to use the Windows message loop. It also works, but again it only reports the ClockChanged event, and nothing else - including the Completed event, which I think should obviously be raised at the end of the clip. I have to confess that I am a bit confused about why polling MediaEventEx.GetEvent() is coming up dry... Any thoughts?
|
|
|
|
|
Update: I tested with a few calls that generate events, and sure enough both techniques were capturing the events as expected. The problem is that I am still not getting the "Completed" event when the clip finishes. Don't know why yet. Later...
|
|
|
|
|
Hi - I've been trying to send you some sample code on how to get events working with the video and DirectShow, but it seems that your email isn't working. I've tried twice now and received Delivery Notification Errors both times. Anyway I've uploaded the code to my FTP server - http://www.blueprintgames.com/developers/alex/misc/DxPlay.zip - if you'd like to take a look. I believe it's all working, since it's part of a sample library for DirectShow.NET. Good luck!
|
|
|
|
|
Thanks. I got it, and have used the event notification technique from it. It gives the same outcome as the WaitForSingleObject technique, but no P/Invoke is needed. I am still not getting the "Complete" event, so I am still trying to sort out looping. Also, Run, Pause, Stop are behaving badly... More work needed...
|
|
|
|
|
Hmm... these seem like fairly major problems. I wonder if there's just part of the setup code that's causing all this. Well if you're still stuck on this soon feel free to send the working code to me and I'll see what I can do.
|
|
|
|
|
Hey, just checking up on your progress with the code again. If you're really stumped, feel free to send me an email as I've mentioned, otherwise it would be good to hear how you've sorted our these issues.
|
|
|
|
|
Thanks for the offer of help; I am still stumped on the reason why I am not getting the "Completed" event when I think I should, and any hints would be welcome. Let me clean up some of the junk from my working code, and I will send it to you.
I have however made (fairly) good progress on the rest of the issues after digging into the DirectShow documentation and trying a half dozen different variations on the filter graphs to see if I could get some of the "not implemented" functionality with a different combination of filters. I have working graphs for .wmv and .avi; I have not tested .mpeg yet.
|
|
|
|