VideoPlayerGame.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Content;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Input;
  7. using Microsoft.Xna.Framework.Media;
  8. namespace VideoPlayer
  9. {
  10. /// <summary>
  11. /// This is the main type for your game
  12. /// </summary>
  13. public class VideoPlayerGame : Game
  14. {
  15. GraphicsDeviceManager graphics;
  16. SpriteBatch spriteBatch;
  17. SpriteFont font;
  18. Video video;
  19. Microsoft.Xna.Framework.Media.VideoPlayer videoPlayer;
  20. bool playVideo = false;
  21. public VideoPlayerGame ()
  22. {
  23. graphics = new GraphicsDeviceManager (this);
  24. Content.RootDirectory = "Content";
  25. graphics.PreferMultiSampling = true;
  26. #if MOBILE
  27. graphics.IsFullScreen = true;
  28. #endif
  29. graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
  30. }
  31. /// <summary>
  32. /// Allows the game to perform any initialization it needs to before starting to run.
  33. /// This is where it can query for any required services and load any non-graphic
  34. /// related content. Calling base.Initialize will enumerate through any components
  35. /// and initialize them as well.
  36. /// </summary>
  37. protected override void Initialize ()
  38. {
  39. // TODO: Add your initialization logic here
  40. base.Initialize ();
  41. }
  42. /// <summary>
  43. /// LoadContent will be called once per game and is the place to load
  44. /// all of your content.
  45. /// </summary>
  46. protected override void LoadContent ()
  47. {
  48. // Create a new SpriteBatch, which can be used to draw textures.
  49. spriteBatch = new SpriteBatch (GraphicsDevice);
  50. // TODO: use this.Content to load your game content here
  51. font = Content.Load<SpriteFont> ("font");
  52. video = Content.Load<Video> ("sintel_trailer");
  53. videoPlayer = new Microsoft.Xna.Framework.Media.VideoPlayer();
  54. playVideo = true;
  55. }
  56. /// <summary>
  57. /// Allows the game to run logic such as updating the world,
  58. /// checking for collisions, gathering input, and playing audio.
  59. /// </summary>
  60. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  61. protected override void Update (GameTime gameTime)
  62. {
  63. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  64. {
  65. Exit();
  66. }
  67. // TODO: Add your update logic here
  68. if (playVideo)
  69. {
  70. if (videoPlayer.State == MediaState.Stopped)
  71. {
  72. videoPlayer.Play(video);
  73. playVideo = false;
  74. }
  75. }
  76. base.Update (gameTime);
  77. }
  78. /// <summary>
  79. /// This is called when the game should draw itself.
  80. /// </summary>
  81. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  82. protected override void Draw (GameTime gameTime)
  83. {
  84. graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
  85. // Won't be visible until we hide the movie
  86. spriteBatch.Begin();
  87. spriteBatch.DrawString(font, "Video has ended, let the Game BEGIN!!", new Vector2 (50, 40), Color.Red);
  88. spriteBatch.End();
  89. }
  90. }
  91. }