Skip to content

Commit

Permalink
Media Toggle Command
Browse files Browse the repository at this point in the history
  • Loading branch information
PaciStardust committed Jan 1, 2023
1 parent cf13e8d commit 74b6363
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions OscMultitool/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public int PortListen
public string AddressMediaRewind { get; set; } = "/avatar/parameters/MediaRewind";
public string AddressMediaSkip { get; set; } = "/avatar/parameters/MediaSkip";
public string AddressMediaInfo { get; set; } = "/avatar/parameters/MediaInfo";
public string AddressMediaToggle { get; set; } = "/avatar/parameters/MediaToggle";

//Counters
public bool ShowCounterNotifications { get; set; } = false;
Expand Down
14 changes: 12 additions & 2 deletions OscMultitool/Services/Api/Media.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ private enum MediaCommandType
Unpause,
Rewind,
Skip,
Info
Info,
TogglePlayback
}

/// <summary>
Expand All @@ -170,7 +171,9 @@ private enum MediaCommandType
{ "info", MediaCommandType.Info },
{ "current", MediaCommandType.Info },
{ "status", MediaCommandType.Info },
{ "now", MediaCommandType.Info }
{ "now", MediaCommandType.Info },

{ "toggle", MediaCommandType.TogglePlayback },
};

/// <summary>
Expand Down Expand Up @@ -198,6 +201,8 @@ public static bool HandleOscMediaCommands(string address)

if (address == Config.Osc.AddressMediaInfo)
command = MediaCommandType.Info;
else if (address == Config.Osc.AddressMediaToggle)
command = MediaCommandType.TogglePlayback;
else if (address == Config.Osc.AddressMediaPause)
command = MediaCommandType.Pause;
else if (address == Config.Osc.AddressMediaRewind)
Expand All @@ -222,6 +227,11 @@ private async static Task HandleMediaCommand(MediaCommandType command)

switch (command)
{
case MediaCommandType.TogglePlayback:
if (await _session.TryTogglePlayPauseAsync())
Logger.Log("Toggled media playback");
return;

case MediaCommandType.Pause:
if (await _session.TryPauseAsync())
Logger.Log("Paused media playback");
Expand Down
3 changes: 3 additions & 0 deletions OscMultitool/Ui/Pages/PageOsc.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<TextBlock Style="{DynamicResource HTextBlock}" Text="Trigger Media Info"/>
<TextBox Text="{Binding Osc.AddressMediaInfo, Source={x:Static local:Config.Data}}" Style="{StaticResource HTextBoxLong}" Tag="Address..." PreviewKeyDown="AddressModified"/>

<TextBlock Style="{DynamicResource HTextBlock}" Text="Trigger Media Toggle" Margin="0,4,0,0"/>
<TextBox Text="{Binding Osc.AddressMediaToggle, Source={x:Static local:Config.Data}}" Style="{StaticResource HTextBoxLong}" Tag="Address..." PreviewKeyDown="AddressModified"/>

<TextBlock Style="{DynamicResource HTextBlock}" Text="Trigger Media Pause" Margin="0,4,0,0"/>
<TextBox Text="{Binding Osc.AddressMediaPause, Source={x:Static local:Config.Data}}" Style="{StaticResource HTextBoxLong}" Tag="Address..." PreviewKeyDown="AddressModified"/>

Expand Down

0 comments on commit 74b6363

Please sign in to comment.