Saturday, October 23, 2010

XNA Tutorial: How to Add a Song, Background and Video

Here is the code

Texture2D background; Video video; VideoPlayer player = new VideoPlayer(); Song song; bool playerStarted = false;
Vector2 backPos = Vector2.Zero; Texture2D videoT;
// Load the content
song = Content.Load<Song>("Not As It Seems");
background = Content.Load<Texture2D>("Desert");
video = Content.Load<Video>("Wildlife");
player.Play(video);

// Play a song
if (player.State == MediaState.Stopped)
{
    if (MediaPlayer.State == MediaState.Stopped)
    {
        if (playerStarted)
            this.Exit();
        MediaPlayer.Play(song);
        playerStarted = true;
    }
}

// Draw the frames of the video and the othr sprites
if (player.State != MediaState.Stopped)
    videoT = player.GetTexture();
Rectangle screen = new Rectangle(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Y,
    GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
if (videoT != null)
    spriteBatch.Draw(videoT, screen, Color.White);
if (player.State == MediaState.Stopped)
{
    spriteBatch.Draw(background, backPos, Color.White);
    spriteBatch.Draw(mytexture, sPos, Color.White);
    spriteBatch.Draw(ball, bPos, Color.White);
}
spriteBatch.End();

Or download the solution

1 comment:

  1. music hits This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.

    ReplyDelete