A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.IO;
5using System.Threading;
6using System.Threading.Tasks;
7using osu.Framework.Graphics;
8using osu.Framework.Graphics.Video;
9using osu.Framework.IO.Network;
10
11namespace osu.Framework.Tests.Visual.Sprites
12{
13 internal class TestVideo : Video
14 {
15 private static MemoryStream consumeVideoStream()
16 {
17 var wr = new WebRequest("https://assets.ppy.sh/media/landing.mp4");
18 Task.Run(() => wr.PerformAsync());
19
20 while (!wr.Completed)
21 Thread.Sleep(100);
22
23 var videoStream = new MemoryStream();
24 wr.ResponseStream.CopyTo(videoStream);
25 videoStream.Position = 0;
26 return videoStream;
27 }
28
29 public TestVideo(bool startAtCurrentTime = true)
30 : base(consumeVideoStream(), startAtCurrentTime)
31 {
32 }
33
34 private bool? useRoundedShader;
35
36 public bool? UseRoundedShader
37 {
38 get => useRoundedShader;
39 set
40 {
41 useRoundedShader = value;
42 Invalidate(Invalidation.DrawNode);
43 }
44 }
45
46 public override Drawable CreateContent() => Sprite = new TestVideoSprite(this) { RelativeSizeAxes = Axes.Both };
47
48 private class TestVideoSprite : VideoSprite
49 {
50 private readonly TestVideo video;
51
52 public TestVideoSprite(TestVideo video)
53 : base(video)
54 {
55 this.video = video;
56 }
57
58 protected override DrawNode CreateDrawNode() => new TestVideoSpriteDrawNode(video);
59 }
60
61 private class TestVideoSpriteDrawNode : VideoSpriteDrawNode
62 {
63 private readonly TestVideo source;
64
65 protected override bool RequiresRoundedShader => useRoundedShader ?? base.RequiresRoundedShader;
66
67 private bool? useRoundedShader;
68
69 public TestVideoSpriteDrawNode(TestVideo source)
70 : base(source)
71 {
72 this.source = source;
73 }
74
75 public override void ApplyState()
76 {
77 base.ApplyState();
78
79 useRoundedShader = source.UseRoundedShader;
80 }
81 }
82 }
83}