XNA プロジェクトにビデオを読み込んで再生しました。唯一の問題は、縦に半分にカットされていることです。ビデオのサイズは 800x600 で、ゲームも 800x600 です。最初は誤って 640x480 バージョンのビデオをコンテンツに入れましたが、その後 800x600 に修正しました。ただし、1/2 の垂直方向は修正されませんでした。640x480 の xnb がまだそこにあり、ロードされているのではないかと思いました。私はそれを探してみて、関連していると思われるものはすべて削除しましたが、それもうまくいきませんでした. これは、ビデオの半分のスクリーンショットです。
これが私のコードです:
namespace Bloxel
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public int WIDTH = 800;
public int HEIGHT = 600;
Video splash;
VideoPlayer player;
Texture2D videoTexture;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = WIDTH;
graphics.PreferredBackBufferHeight = HEIGHT;
graphics.ApplyChanges();
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
splash = Content.Load<Video>("splash");
player = new VideoPlayer();
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (player.State == MediaState.Stopped)
{
player.IsLooped = false;
player.Play(splash);
}
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
if (player.State != MediaState.Stopped)
videoTexture = player.GetTexture();
Rectangle screen = new Rectangle(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
if (videoTexture != null)
{
spriteBatch.Begin();
spriteBatch.Draw(videoTexture, screen, Color.White);
spriteBatch.End();
}
base.Draw(gameTime);
}
}
}