-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoManager.cs
47 lines (44 loc) · 1.8 KB
/
VideoManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SonicDronsEngine
{
public class VideoManager
{
public VideoPlayer videoPlayer;
GraphicsDeviceManager graphics;
Texture2D videoTexture;
public VideoManager(GraphicsDeviceManager _graphics)
{
videoPlayer = new VideoPlayer();
graphics = _graphics;
}
public void PlayVideoOnFullScreen(SpriteBatch spriteBatch, Video video)
{
if (videoPlayer.State != MediaState.Stopped)
videoTexture = videoPlayer.GetTexture();
Rectangle screen = new Rectangle(0,
0,
graphics.PreferredBackBufferWidth,
graphics.PreferredBackBufferHeight);
if (videoTexture != null)
{
float scaleFactor = 1,
scaleFactorW = (float)graphics.PreferredBackBufferWidth / 1280,
scaleFactorH = (float)graphics.PreferredBackBufferHeight / 720;
if (1280 * scaleFactorH > graphics.PreferredBackBufferWidth)
scaleFactor = scaleFactorW;
if (720 * scaleFactorW > graphics.PreferredBackBufferHeight)
scaleFactor = scaleFactorH;
Vector2 videoPosition = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
Vector2 videoOrigin = new Vector2(1280 / 2, 720 / 2);
spriteBatch.Draw(videoTexture, videoPosition, new Rectangle(0, 0, 1280, 720), Color.White, 0, videoOrigin, scaleFactor, SpriteEffects.None, 0);
}
}
}
}