Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm mostly just working on this as a hobbyist thing, but here's my problem: I got a bit excited over finding the 'Video' and 'VideoPlayer' classes in XNA 4, and hoped to make a game that works a little bit like how Myst does - with very active backgrounds, but no actual 3D graphics. (Technically, Myst 1 had static backgrounds, but maybe you get the idea) I threw together a small test game in XNA, with a pretty simple WMV included.

The problem I have is that it's not quite responsive enough. I'd like my system to be able to swap the current video in a millisecond, so that the player could click a contraption in the background and instantly see it move. Right now, when I press my trigger key that calls this code:

    private void cycleVideos()
    {
        videoIndex++;
        if (videoIndex == videos.Count)
        {
            videoIndex = 0;
        }
        activeVideo = videos[videoIndex];

        vp.Stop(); // Couldn't find a 'Seek(0)' method
        vp.Play(activeVideo);

    }

...it takes about a full second to re-seek the position it needs, and start playing again. In this example, I hadn't even encoded my video to the HD (1920x1080) resolution I had been planning on. I can understand if XNA's video system is really only meant for full cutscenes between missions or that sort of thing; I'm willing to use additional memory to have large parts of my videos cached, or even include a bit of a dynamic caching system so that things are loaded/unloaded over time (after all, this is the main visual of the game), but I'd like to hear if I have any decent options to accomplish this.

I'm also somewhat open to the idea of using a different engine or coding environment entirely.

EDIT: I've been doing some experimentation in my eagerness to solve this. I can definitely get some faster responsiveness by avoiding the 'stop()' calls, and by maintaining multiple instances of VideoPlayer. A paused video will resume much more quickly; and it's possible to play(), then pause() a video immediately (at the beginning of the program, in order to 'cache' it). It's not a full solution yet - I want to be able to seek back to the beginning of a video, and I still feel like there should be some possibility of that somewhere.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

To seek you should use the PlayPosition property of VideoPlayer (http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.videoplayer.playposition%28v=xnagamestudio.31%29.aspx)

I think the best way to do this, if you want quick turnaround time, it to cache the VideoPlayer instances.

Another idea would be just to cache the textures for x seconds, while the VideoPlayer reloads the new file, then switch over to take the textures from the loaded one. To expand on this idea: you can make a new class CachedVideo which will be a "lightweight" wrapper over Video and VideoPlayer. Here, you will implement the Update and Draw loops in a 'producer-consumer' pattern, using a circular buffer:

  • Update takes a texture and puts it into the buffer
  • Draw takes one texture and draws it.

To allow a period of pre-buffering, you could specify a certain time amount to execute just the Update loop before actually executing the Draw call. This way, even if you need to loop the video, you'll already have something like 3-5 seconds of pre-buffering.

One problem still arises here is that the initial pre-buffering still takes a while. You could mitigate it by letting some sort of load screen to be shown in the meantime.

share|improve this answer
    
Thank you very much for the answer! Sadly...if you look closely at that documentation link you gave me, PlayPosition is a read-only property. (It defines get;, not set;) I'm currently considering a system that caches VideoPlayer objects, but probably the biggest killer for me is that looping a video via IsLooped will take 1-2 seconds to actually re-seek the beginning of the video. As a result, I'm actually looking into re-designs of my game that primarily use basic spritesheet animations on-screen (ie, a character's mouth), with occasional video usage. Caching textures is an interesting idea. –  Katana314 May 22 '13 at 13:24
    
Oh. I am sorry. Well, I've looked in the XNA source code and it seems underneath it invokes the Windows Media Player COM interface (or something like that). However, I've expanded my previous answer regarding the caching :) –  Timotei May 22 '13 at 14:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.