Skip to content

Commit

Permalink
implement video loop
Browse files Browse the repository at this point in the history
properly return nui callback
twitch mute if out of range fix
twitch mature audience fix
  • Loading branch information
Thiago Zimmermann committed Jul 13, 2020
1 parent fd8a90a commit 368d08c
Show file tree
Hide file tree
Showing 24 changed files with 993 additions and 669 deletions.
23 changes: 14 additions & 9 deletions src/Hypnonema.Client/BrowserStateHelperScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,35 @@ public static async Task<DuiState> GetLastState(int timeout = 5500)

private CallbackDelegate GetStateResponse(IDictionary<string, object> args, CallbackDelegate callback)
{
bool.TryParse(args.FirstOrDefault(arg => arg.Key == "paused").Value?.ToString(), out var paused);
float.TryParse(args.FirstOrDefault(arg => arg.Key == "currentTime").Value?.ToString(), out var currentTime);
float.TryParse(args.FirstOrDefault(arg => arg.Key == "duration").Value?.ToString(), out var duration);
bool.TryParse(args.FirstOrDefault(arg => arg.Key == "ended").Value?.ToString(), out var ended);
var currentSource = args.FirstOrDefault(arg => arg.Key == "currentSource").Value?.ToString();

var screenName = args.FirstOrDefault(arg => arg.Key == "screenName").Value?.ToString();
var screenName = ArgsReader.GetArgKeyValue<string>(args, "screenName");
if (string.IsNullOrEmpty(screenName))
{
Debug.WriteLine("error: received state response without valid screenName.");
Debug.WriteLine("Warning: received state response without valid screenName.");
callback("");
return callback;
}

var paused = ArgsReader.GetArgKeyValue<bool>(args, "paused");
var repeat = ArgsReader.GetArgKeyValue<bool>(args, "repeat");
var currentTime = ArgsReader.GetArgKeyValue<float>(args, "currentTime");
var duration = ArgsReader.GetArgKeyValue<float>(args, "duration");
var ended = ArgsReader.GetArgKeyValue<bool>(args, "ended");
var currentSource = ArgsReader.GetArgKeyValue<string>(args, "currentSource");

var state = new DuiState
{
CurrentTime = currentTime,
ScreenName = screenName,
Ended = ended,
IsPaused = paused,
Duration = duration,
CurrentSource = currentSource
CurrentSource = currentSource,
Repeat = repeat
};

StateQueue.Enqueue(state);

callback("OK");
return callback;
}
}
Expand Down
335 changes: 95 additions & 240 deletions src/Hypnonema.Client/ClientScript.cs

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/Hypnonema.Client/Graphics/DuiBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Init(string screenName, string posterUrl)
{
this.SendMessage(new { type = "init", screenName, posterUrl });
}

public void Pause()
{
this.SendMessage(new { type = "pause" });
Expand Down Expand Up @@ -105,6 +105,11 @@ public void SetVolume(float volume)
this.SendMessage(new { type = "volume", volume = volume / 100 });
}

public void Mute(bool muted)
{
this.SendMessage(new { type = "mute", muted });
}

public void Stop()
{
this.SendMessage(new { type = "stop" });
Expand Down Expand Up @@ -146,14 +151,14 @@ public void Toggle3DAudio(bool value)
this.SendMessage(new { type = "toggle3DAudio", enabled = value });
}

public void ToggleReplay(bool toggle)
public void ToggleRepeat()
{
this.SendMessage(new { type = "toggleReplay", value = toggle });
this.SendMessage(new { type = "toggleRepeat" });
}

public void Update(bool paused, float currentTime, string currentSource)
public void Update(bool paused, float currentTime, string currentSource, bool repeat)
{
this.SendMessage(new { type = "update", paused, currentTime, src = currentSource });
this.SendMessage(new { type = "update", paused, currentTime, src = currentSource, repeat });
}
}
}
3 changes: 2 additions & 1 deletion src/Hypnonema.Client/Hypnonema.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Core.Client, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\CitizenFX.Core.Client.1.0.2432\lib\net45\CitizenFX.Core.Client.dll</HintPath>
<HintPath>..\..\packages\CitizenFX.Core.Client.1.0.2695\lib\net45\CitizenFX.Core.Client.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -53,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ArgsReader.cs" />

This comment has been minimized.

Copy link
@Salzian

Salzian Jul 26, 2020

This file is missing in the latest commit!

<Compile Include="AudioTickData.cs" />
<Compile Include="BrowserStateHelperScript.cs" />
<Compile Include="ClientScript.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/Hypnonema.Client/Players/IVideoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public interface IVideoPlayer : IDisposable

void Stop();

void SynchronizeState(bool paused, float currentTime, string currentSource);
void SynchronizeState(bool paused, float currentTime, string currentSource, bool repeat);

void ToggleReplay(bool replay);
void ToggleRepeat();
}
}
8 changes: 4 additions & 4 deletions src/Hypnonema.Client/Players/VideoPlayer2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ public void Stop()
this.Browser.Stop();
}

public void SynchronizeState(bool paused, float currentTime, string currentSource)
public void SynchronizeState(bool paused, float currentTime, string currentSource, bool repeat)
{
this.Browser.Update(paused, currentTime, currentSource);
this.Browser.Update(paused, currentTime, currentSource, repeat);
}

public void Toggle3DAudio(bool value)
{
this.Browser.Toggle3DAudio(value);
}

public void ToggleReplay(bool replay)
public void ToggleRepeat()
{
this.Browser.ToggleReplay(replay);
this.Browser.ToggleRepeat();
}

private static Prop GetClosestObjectOfType(float radius, uint modelHash)
Expand Down
8 changes: 4 additions & 4 deletions src/Hypnonema.Client/Players/VideoPlayer3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ public void Stop()
this.Browser.Stop();
}

public void SynchronizeState(bool paused, float currentTime, string currentSource)
public void SynchronizeState(bool paused, float currentTime, string currentSource, bool repeat)
{
this.Browser.Update(paused, currentTime, currentSource);
this.Browser.Update(paused, currentTime, currentSource, repeat);
}

public void Toggle3DAudio(bool value)
{
this.Browser.Toggle3DAudio(value);
}

public void ToggleReplay(bool replay)
public void ToggleRepeat()
{
this.Browser.ToggleReplay(replay);
this.Browser.ToggleRepeat();
}

private float GetSoundFactor(float distance)
Expand Down
14 changes: 11 additions & 3 deletions src/Hypnonema.Client/Players/VideoPlayerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<IVideoPlayer> CreateVideoPlayerAsync(Shared.Models.Screen scre
browser.CreateRuntimeTexture();
await BaseScript.Delay(1000);

Debug.WriteLine("sending init..");
// Debug.WriteLine("sending init..");
browser.Init(screen.Name, this.posterUrl);

if (!screen.Is3DRendered)
Expand Down Expand Up @@ -155,11 +155,19 @@ public async Task SynchronizeState(DuiState state, Shared.Models.Screen screen)
return;
}

Debug.WriteLine("Synchronizing..");
player.SynchronizeState(state.IsPaused, state.CurrentTime, state.CurrentSource);
Debug.WriteLine($"Synchronizing: {screen.Name}");
player.SynchronizeState(state.IsPaused, state.CurrentTime, state.CurrentSource, state.Repeat);
this.VideoPlayers.Add(player);
}

public void ToggleRepeat(string screenName)
{
var player = this.VideoPlayers.FirstOrDefault(s => s.ScreenName == screenName);
if (player == null) return;

player.ToggleRepeat();
}

private static VideoPlayer2D CreateVideoPlayer2D(DuiBrowser browser, Shared.Models.Screen screen)
{
var renderTarget = new RenderTarget(
Expand Down
5 changes: 2 additions & 3 deletions src/Hypnonema.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="CitizenFX.Core.Client" version="1.0.2432" targetFramework="net452" />
<package id="Nerdbank.GitVersioning" version="3.1.91" targetFramework="net452" developmentDependency="true" />
<package id="CitizenFX.Core.Client" version="1.0.2695" targetFramework="net452" />
<package id="Nerdbank.GitVersioning" version="3.1.91" targetFramework="net452" developmentDependency="true" />
</packages>
Loading

0 comments on commit 368d08c

Please sign in to comment.