-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebGLでのビデオ再生をJavaScriptに委譲できるようにする (#9)
- Loading branch information
1 parent
84f1b10
commit 215f874
Showing
80 changed files
with
7,003 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Extreal.Core.Common.System; | ||
using Extreal.Core.Logging; | ||
using UniRx; | ||
|
||
namespace Extreal.Integration.Web.Common.Video | ||
{ | ||
/// <summary> | ||
/// Class that handles VideoPlayer. | ||
/// </summary> | ||
public abstract class EVideoPlayer : DisposableBase | ||
{ | ||
private static readonly ELogger Logger = LoggingManager.GetLogger(nameof(EVideoPlayer)); | ||
|
||
/// <summary> | ||
/// Invokes immediately after the preparation is completed. | ||
/// </summary> | ||
public IObservable<Unit> OnPrepareCompleted => onPrepareCompleted.AddTo(Disposables); | ||
[SuppressMessage("Usage", "CC0033")] | ||
private readonly Subject<Unit> onPrepareCompleted = new Subject<Unit>(); | ||
|
||
/// <summary> | ||
/// Fires the OnPrepareCompleted. | ||
/// </summary> | ||
protected void FireOnPrepareCompleted() | ||
{ | ||
if (Logger.IsDebug()) | ||
{ | ||
Logger.LogDebug(nameof(FireOnPrepareCompleted)); | ||
} | ||
onPrepareCompleted.OnNext(Unit.Default); | ||
} | ||
|
||
/// <summary> | ||
/// <para>Invokes immediately after an error has occurred.</para> | ||
/// Arg: Error message | ||
/// </summary> | ||
public IObservable<string> OnErrorReceived => onErrorReceived.AddTo(Disposables); | ||
[SuppressMessage("Usage", "CC0033")] | ||
private readonly Subject<string> onErrorReceived = new Subject<string>(); | ||
|
||
/// <summary> | ||
/// Fires the OnErrorReceived. | ||
/// </summary> | ||
/// <param name="message"></param> | ||
protected void FireOnErrorReceived(string message) | ||
{ | ||
if (Logger.IsDebug()) | ||
{ | ||
Logger.LogDebug($"{nameof(FireOnErrorReceived)}: message={message}"); | ||
} | ||
onErrorReceived.OnNext(message); | ||
} | ||
|
||
/// <summary> | ||
/// Disposables. | ||
/// </summary> | ||
protected CompositeDisposable Disposables { get; } = new CompositeDisposable(); | ||
|
||
/// <summary> | ||
/// Video url. | ||
/// </summary> | ||
/// <value>Video url.</value> | ||
protected string Url { get; private set; } | ||
|
||
/// <summary> | ||
/// Video length. | ||
/// </summary> | ||
public abstract double Length { get; } | ||
|
||
/// <summary> | ||
/// Sets the video url. | ||
/// </summary> | ||
/// <param name="url">Video url.</param> | ||
public void SetUrl(string url) => Url = url; | ||
|
||
/// <summary> | ||
/// Sets the playback position. | ||
/// </summary> | ||
/// <param name="time">Playback position.</param> | ||
public abstract void SetTime(double time); | ||
|
||
/// <summary> | ||
/// Prepares the VideoPlayer. | ||
/// </summary> | ||
public abstract void Prepare(); | ||
|
||
/// <summary> | ||
/// Plays the video. | ||
/// </summary> | ||
public abstract void Play(); | ||
|
||
/// <summary> | ||
/// Pauses the video. | ||
/// </summary> | ||
public abstract void Pause(); | ||
|
||
/// <summary> | ||
/// Stops the video. | ||
/// </summary> | ||
public abstract void Stop(); | ||
|
||
/// <summary> | ||
/// Sets the audio volume. | ||
/// </summary> | ||
/// <param name="volume">Audio volume (0.0 - 1.0).</param> | ||
/// <param name="trackIndex">Track index.</param> | ||
public abstract void SetAudioVolume(float volume, ushort trackIndex = default); | ||
|
||
/// <inheritdoc/> | ||
protected sealed override void ReleaseManagedResources() | ||
{ | ||
DoReleaseManagedResources(); | ||
Disposables.Dispose(); | ||
} | ||
|
||
/// <summary> | ||
/// Releases managed resources. | ||
/// </summary> | ||
protected abstract void DoReleaseManagedResources(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using UnityEngine; | ||
using UnityEngine.Video; | ||
|
||
namespace Extreal.Integration.Web.Common.Video | ||
{ | ||
/// <summary> | ||
/// Class that provides EVideoPlayer. | ||
/// </summary> | ||
public static class EVideoPlayerProvider | ||
{ | ||
/// <summary> | ||
/// Provides the EVideoPlayer. | ||
/// </summary> | ||
/// <remarks> | ||
/// Creates and returns a EVideoPlayer for Native (C#) or WebGL (JavaScript) depending on the platform. | ||
/// </remarks> | ||
/// <param name="videoPlayer">Video player for Native (C#)</param> | ||
/// <param name="targetRenderTexture">Target render texture for WebGL</param> | ||
/// <returns></returns> | ||
[SuppressMessage("Usage", "CC0038"), SuppressMessage("Usage", "IDE0022"), SuppressMessage("Usage", "CC0057")] | ||
public static EVideoPlayer Provide(VideoPlayer videoPlayer, RenderTexture targetRenderTexture) | ||
{ | ||
#if !UNITY_WEBGL || UNITY_EDITOR | ||
return new NativeEVideoPlayer(videoPlayer); | ||
#else | ||
return new WebGLEVideoPlayer(targetRenderTexture); | ||
#endif | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using UnityEngine.Video; | ||
|
||
namespace Extreal.Integration.Web.Common.Video | ||
{ | ||
public class NativeEVideoPlayer : EVideoPlayer | ||
{ | ||
private void PrepareCompletedEventHandler(VideoPlayer videoPlayer) | ||
=> FireOnPrepareCompleted(); | ||
|
||
private void ErrorReceivedEventHandler(VideoPlayer source, string message) | ||
=> FireOnErrorReceived(message); | ||
|
||
public override double Length | ||
=> videoPlayer.length; | ||
|
||
private readonly VideoPlayer videoPlayer; | ||
|
||
public NativeEVideoPlayer(VideoPlayer videoPlayer) | ||
{ | ||
this.videoPlayer = videoPlayer; | ||
this.videoPlayer.prepareCompleted += PrepareCompletedEventHandler; | ||
this.videoPlayer.errorReceived += ErrorReceivedEventHandler; | ||
} | ||
|
||
protected override void DoReleaseManagedResources() | ||
{ | ||
videoPlayer.prepareCompleted -= PrepareCompletedEventHandler; | ||
videoPlayer.errorReceived -= ErrorReceivedEventHandler; | ||
if (videoPlayer.renderMode == VideoRenderMode.RenderTexture) | ||
{ | ||
videoPlayer.targetTexture.Release(); | ||
} | ||
} | ||
|
||
public override void SetTime(double time) | ||
=> videoPlayer.time = time; | ||
|
||
public override void Prepare() | ||
{ | ||
videoPlayer.url = Url; | ||
videoPlayer.Prepare(); | ||
} | ||
|
||
public override void Play() | ||
=> videoPlayer.Play(); | ||
|
||
public override void Pause() | ||
=> videoPlayer.Pause(); | ||
|
||
public override void Stop() | ||
=> videoPlayer.Stop(); | ||
|
||
public override void SetAudioVolume(float volume, ushort trackIndex = default) | ||
=> videoPlayer.SetDirectAudioVolume(trackIndex, volume); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.