osu/osu.Game/Storyboards/Drawables/DrawableStoryboardVideo.cs

66 lines
1.9 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Video;
using osu.Game.Beatmaps;
namespace osu.Game.Storyboards.Drawables
{
2020-03-11 08:55:20 +00:00
public class DrawableStoryboardVideo : CompositeDrawable
{
public readonly StoryboardVideo Video;
private Video video;
public override bool RemoveWhenNotAlive => false;
public DrawableStoryboardVideo(StoryboardVideo video)
{
Video = video;
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader(true)]
2020-03-11 05:50:20 +00:00
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
{
string path = beatmap.Value.BeatmapSetInfo?.Files.Find(f => f.Filename.Equals(Video.Path, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
if (path == null)
return;
var stream = textureStore.GetStream(path);
if (stream == null)
return;
InternalChild = video = new Video(stream, false)
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-03-11 06:11:54 +00:00
Alpha = 0,
2020-03-11 08:55:20 +00:00
};
}
2020-03-11 05:50:20 +00:00
protected override void LoadComplete()
{
2020-03-11 06:11:54 +00:00
base.LoadComplete();
if (video == null) return;
using (video.BeginAbsoluteSequence(Video.StartTime))
{
Schedule(() => video.PlaybackPosition = Time.Current - Video.StartTime);
video.FadeIn(500);
}
}
}
}