Game1.cs 3.0 KB

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