Tiny little tweak to allow that if there is a live stream it looks at the duration it sees that it is zero and for SMTC it does not show the status that it is paused it merely shows that it is actively playing It also made a tiny change in the GUI for the time it shows the word live which is kind of cool
This commit is contained in:
+103
-6
@@ -32,6 +32,7 @@ namespace RadioDJViewer
|
|||||||
private double _playbackElapsedSeconds = 0;
|
private double _playbackElapsedSeconds = 0;
|
||||||
private double _playbackDurationSeconds = 0;
|
private double _playbackDurationSeconds = 0;
|
||||||
private bool _playbackPaused = true;
|
private bool _playbackPaused = true;
|
||||||
|
private bool _playbackIsLiveStream = false;
|
||||||
private DateTime _playbackBaseUtc = DateTime.UtcNow;
|
private DateTime _playbackBaseUtc = DateTime.UtcNow;
|
||||||
private string selectedFolderPath = string.Empty;
|
private string selectedFolderPath = string.Empty;
|
||||||
private string outputFolderPath = string.Empty;
|
private string outputFolderPath = string.Empty;
|
||||||
@@ -182,6 +183,7 @@ namespace RadioDJViewer
|
|||||||
_playbackElapsedSeconds = 0;
|
_playbackElapsedSeconds = 0;
|
||||||
_playbackDurationSeconds = 0;
|
_playbackDurationSeconds = 0;
|
||||||
_playbackPaused = true;
|
_playbackPaused = true;
|
||||||
|
_playbackIsLiveStream = false;
|
||||||
_playbackTrackKey = string.Empty;
|
_playbackTrackKey = string.Empty;
|
||||||
time_data_label.Text = "No Data";
|
time_data_label.Text = "No Data";
|
||||||
WidgetServer.CachedElapsed = "0";
|
WidgetServer.CachedElapsed = "0";
|
||||||
@@ -478,13 +480,34 @@ namespace RadioDJViewer
|
|||||||
{
|
{
|
||||||
double elapsedSeconds;
|
double elapsedSeconds;
|
||||||
double durationSeconds;
|
double durationSeconds;
|
||||||
if (!TryParseSeconds(elapsedText, out elapsedSeconds) || !TryParseSeconds(durationText, out durationSeconds) || durationSeconds <= 0)
|
|
||||||
|
bool hasDuration = TryParseSeconds(durationText, out durationSeconds);
|
||||||
|
bool isLiveStream = hasDuration && durationSeconds <= 0;
|
||||||
|
|
||||||
|
if (isLiveStream)
|
||||||
|
{
|
||||||
|
playbackTimer.Stop();
|
||||||
|
_playbackTrackKey = trackKey ?? string.Empty;
|
||||||
|
_playbackElapsedSeconds = 0;
|
||||||
|
_playbackDurationSeconds = 0;
|
||||||
|
_playbackPaused = false;
|
||||||
|
_playbackIsLiveStream = true;
|
||||||
|
time_data_label.Text = "LIVE";
|
||||||
|
WidgetServer.CachedElapsed = "0";
|
||||||
|
WidgetServer.CachedDuration = "0";
|
||||||
|
WidgetServer.CachedTime = "LIVE";
|
||||||
|
WidgetServer.CachedPaused = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryParseSeconds(elapsedText, out elapsedSeconds) || !hasDuration || durationSeconds <= 0)
|
||||||
{
|
{
|
||||||
playbackTimer.Stop();
|
playbackTimer.Stop();
|
||||||
_playbackTrackKey = trackKey ?? string.Empty;
|
_playbackTrackKey = trackKey ?? string.Empty;
|
||||||
_playbackElapsedSeconds = 0;
|
_playbackElapsedSeconds = 0;
|
||||||
_playbackDurationSeconds = 0;
|
_playbackDurationSeconds = 0;
|
||||||
_playbackPaused = true;
|
_playbackPaused = true;
|
||||||
|
_playbackIsLiveStream = false;
|
||||||
time_data_label.Text = "No Data";
|
time_data_label.Text = "No Data";
|
||||||
WidgetServer.CachedElapsed = "0";
|
WidgetServer.CachedElapsed = "0";
|
||||||
WidgetServer.CachedDuration = "0";
|
WidgetServer.CachedDuration = "0";
|
||||||
@@ -502,6 +525,7 @@ namespace RadioDJViewer
|
|||||||
_playbackDurationSeconds = durationSeconds;
|
_playbackDurationSeconds = durationSeconds;
|
||||||
_playbackBaseUtc = DateTime.UtcNow;
|
_playbackBaseUtc = DateTime.UtcNow;
|
||||||
_playbackPaused = sameTrack && sameElapsed && sameDuration;
|
_playbackPaused = sameTrack && sameElapsed && sameDuration;
|
||||||
|
_playbackIsLiveStream = false;
|
||||||
|
|
||||||
if (_playbackPaused)
|
if (_playbackPaused)
|
||||||
playbackTimer.Stop();
|
playbackTimer.Stop();
|
||||||
@@ -643,7 +667,14 @@ namespace RadioDJViewer
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
System.Diagnostics.Debug.WriteLine($"[SMTC] Resolved artwork path: '{smtcImagePath}' (exists={(!string.IsNullOrWhiteSpace(smtcImagePath) && File.Exists(smtcImagePath))})");
|
System.Diagnostics.Debug.WriteLine($"[SMTC] Resolved artwork path: '{smtcImagePath}' (exists={(!string.IsNullOrWhiteSpace(smtcImagePath) && File.Exists(smtcImagePath))})");
|
||||||
#endif
|
#endif
|
||||||
SmtcService.PublishNowPlaying(titleText, artistText, smtcImagePath, _playbackPaused);
|
SmtcService.PublishNowPlaying(
|
||||||
|
titleText,
|
||||||
|
artistText,
|
||||||
|
smtcImagePath,
|
||||||
|
_playbackPaused,
|
||||||
|
_playbackIsLiveStream,
|
||||||
|
GetCurrentElapsedSeconds(),
|
||||||
|
_playbackDurationSeconds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SmtcService.Disable();
|
SmtcService.Disable();
|
||||||
@@ -675,6 +706,7 @@ namespace RadioDJViewer
|
|||||||
_playbackElapsedSeconds = 0;
|
_playbackElapsedSeconds = 0;
|
||||||
_playbackDurationSeconds = 0;
|
_playbackDurationSeconds = 0;
|
||||||
_playbackPaused = true;
|
_playbackPaused = true;
|
||||||
|
_playbackIsLiveStream = false;
|
||||||
time_data_label.Text = "No Data";
|
time_data_label.Text = "No Data";
|
||||||
WidgetServer.CachedElapsed = "0";
|
WidgetServer.CachedElapsed = "0";
|
||||||
WidgetServer.CachedDuration = "0";
|
WidgetServer.CachedDuration = "0";
|
||||||
@@ -1115,7 +1147,7 @@ namespace RadioDJViewer
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PublishNowPlaying(string title, string artist, string imagePath, bool paused)
|
public static void PublishNowPlaying(string title, string artist, string imagePath, bool paused, bool isLiveStream, double elapsedSeconds, double durationSeconds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1123,12 +1155,17 @@ namespace RadioDJViewer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SetPropertyIfExists(_smtc, "IsEnabled", true);
|
SetPropertyIfExists(_smtc, "IsEnabled", true);
|
||||||
SetPropertyIfExists(_smtc, "IsPlayEnabled", true);
|
SetPropertyIfExists(_smtc, "IsPlayEnabled", !isLiveStream);
|
||||||
SetPropertyIfExists(_smtc, "IsPauseEnabled", true);
|
SetPropertyIfExists(_smtc, "IsPauseEnabled", !isLiveStream);
|
||||||
SetPropertyIfExists(_smtc, "IsStopEnabled", true);
|
SetPropertyIfExists(_smtc, "IsStopEnabled", true);
|
||||||
SetPropertyIfExists(_smtc, "IsNextEnabled", false);
|
SetPropertyIfExists(_smtc, "IsNextEnabled", false);
|
||||||
SetPropertyIfExists(_smtc, "IsPreviousEnabled", false);
|
SetPropertyIfExists(_smtc, "IsPreviousEnabled", false);
|
||||||
SetPlaybackStatus(paused ? "Paused" : "Playing");
|
SetPlaybackStatus(isLiveStream ? "Playing" : (paused ? "Paused" : "Playing"));
|
||||||
|
|
||||||
|
if (isLiveStream)
|
||||||
|
TryClearTimelineProperties();
|
||||||
|
else
|
||||||
|
TryUpdateTimelineProperties(elapsedSeconds, durationSeconds);
|
||||||
|
|
||||||
object updater = GetPropertyValue(_smtc, "DisplayUpdater");
|
object updater = GetPropertyValue(_smtc, "DisplayUpdater");
|
||||||
if (updater == null)
|
if (updater == null)
|
||||||
@@ -1230,6 +1267,66 @@ namespace RadioDJViewer
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void TryUpdateTimelineProperties(double elapsedSeconds, double durationSeconds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_smtc == null || durationSeconds <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
double clampedElapsed = elapsedSeconds;
|
||||||
|
if (clampedElapsed < 0)
|
||||||
|
clampedElapsed = 0;
|
||||||
|
if (clampedElapsed > durationSeconds)
|
||||||
|
clampedElapsed = durationSeconds;
|
||||||
|
|
||||||
|
Type timelineType = Type.GetType("Windows.Media.SystemMediaTransportControlsTimelineProperties, Windows, ContentType=WindowsRuntime");
|
||||||
|
if (timelineType == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
object timeline = Activator.CreateInstance(timelineType);
|
||||||
|
TimeSpan start = TimeSpan.Zero;
|
||||||
|
TimeSpan position = TimeSpan.FromSeconds(clampedElapsed);
|
||||||
|
TimeSpan end = TimeSpan.FromSeconds(durationSeconds);
|
||||||
|
|
||||||
|
SetPropertyIfExists(timeline, "StartTime", start);
|
||||||
|
SetPropertyIfExists(timeline, "MinSeekTime", start);
|
||||||
|
SetPropertyIfExists(timeline, "Position", position);
|
||||||
|
SetPropertyIfExists(timeline, "MaxSeekTime", end);
|
||||||
|
SetPropertyIfExists(timeline, "EndTime", end);
|
||||||
|
|
||||||
|
MethodInfo updateTimelineMethod = _smtc.GetType().GetMethod("UpdateTimelineProperties", BindingFlags.Public | BindingFlags.Instance, null, new[] { timelineType }, null);
|
||||||
|
updateTimelineMethod?.Invoke(_smtc, new[] { timeline });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TryClearTimelineProperties()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_smtc == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Type timelineType = Type.GetType("Windows.Media.SystemMediaTransportControlsTimelineProperties, Windows, ContentType=WindowsRuntime");
|
||||||
|
if (timelineType == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
object timeline = Activator.CreateInstance(timelineType);
|
||||||
|
TimeSpan zero = TimeSpan.Zero;
|
||||||
|
|
||||||
|
SetPropertyIfExists(timeline, "StartTime", zero);
|
||||||
|
SetPropertyIfExists(timeline, "MinSeekTime", zero);
|
||||||
|
SetPropertyIfExists(timeline, "Position", zero);
|
||||||
|
SetPropertyIfExists(timeline, "MaxSeekTime", zero);
|
||||||
|
SetPropertyIfExists(timeline, "EndTime", zero);
|
||||||
|
|
||||||
|
MethodInfo updateTimelineMethod = _smtc.GetType().GetMethod("UpdateTimelineProperties", BindingFlags.Public | BindingFlags.Instance, null, new[] { timelineType }, null);
|
||||||
|
updateTimelineMethod?.Invoke(_smtc, new[] { timeline });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
private static string CreateSmtcThumbnailTempFile(string sourcePath)
|
private static string CreateSmtcThumbnailTempFile(string sourcePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("1.15.0")]
|
[assembly: AssemblyVersion("1.15.1")]
|
||||||
[assembly: AssemblyFileVersion("1.15.0")]
|
[assembly: AssemblyFileVersion("1.15.1")]
|
||||||
|
|||||||
Reference in New Issue
Block a user