xna でビデオを再生するのに問題があります。xna でビデオを再生できません。それは例外をスローします。例外は次のとおりです: System.InvalidOperationException "予期しないエラーが発生しました"。
ここに私のコードがあります:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace VideoGameTest1
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D videotexture;
Video video;
VideoPlayer videoplayer;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
// IsMouseVisible = true;
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);
video = Content.Load<Video>("Wildlife");
videoplayer = new VideoPlayer();
// TODO: use this.Content to load your game content here
}
/// <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
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (videoplayer.State == MediaState.Stopped)
{
videoplayer.IsLooped = true;
videoplayer.Play(video);
}
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
if (videoplayer.State != MediaState.Stopped)
{
videotexture = videoplayer.GetTexture();
}
Rectangle screen = new Rectangle(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
spriteBatch.Begin();
if (videotexture != null)
{
spriteBatch.Draw(videotexture,screen, Color.White);
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
ここで例外がスローされました: videoplayer.Play(video);