Skip to content

Commit

Permalink
v1.0.3.6
Browse files Browse the repository at this point in the history
hopefully prevents DubyaDude/WindowsMediaController#11 error message
  • Loading branch information
VRCWizard committed Mar 6, 2023
1 parent 604893f commit 8766491
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 64 deletions.
153 changes: 94 additions & 59 deletions OSCVRCWiz/Addons/WindowsMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ public class WindowsMedia

public static async Task getWindowsMedia()
{
mediaManager = new MediaManager();
try
{
mediaManager = new MediaManager();

mediaManager.OnAnySessionOpened += MediaManager_OnAnySessionOpened;
mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed;
mediaManager.OnAnyPlaybackStateChanged += MediaManager_OnAnyPlaybackStateChanged;
mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged;

mediaManager.OnAnySessionOpened += MediaManager_OnAnySessionOpened;
mediaManager.OnAnySessionClosed += MediaManager_OnAnySessionClosed;
mediaManager.OnAnyPlaybackStateChanged += MediaManager_OnAnyPlaybackStateChanged;
mediaManager.OnAnyMediaPropertyChanged += MediaManager_OnAnyMediaPropertyChanged;

mediaManager.Start();

mediaManager.Start();
}
catch (Exception ex)
{
OutputText.outputLog("Windows Media Startup Exception: " + ex.Message, Color.Red);
}

// mediaManager.Dispose(); // should dispose manually if nessicary, for instance if I want to stop media completely

Expand Down Expand Up @@ -131,47 +138,61 @@ public static string getMediaDurationHours()
}
public static void MediaManager_OnAnySessionOpened(MediaManager.MediaSession session)
{
getSession= session;
string info = "[Windows Media New Source: " + session.Id + "]";
// var ot = new OutputText();
Task.Run(() => OutputText.outputLog(info));
mediaSourceNew = session.Id;
VoiceWizardWindow.MainFormGlobal.Invoke((MethodInvoker)delegate ()
try
{
bool inThere = false;
for (int i = 0; i < VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Count; i++)
getSession = session;
string info = "[Windows Media New Source: " + session.Id + "]";
// var ot = new OutputText();
Task.Run(() => OutputText.outputLog(info));
mediaSourceNew = session.Id;
VoiceWizardWindow.MainFormGlobal.Invoke((MethodInvoker)delegate ()
{

if (VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items[i].ToString() == session.Id.ToString())
bool inThere = false;
for (int i = 0; i < VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Count; i++)
{
inThere = true;

if (VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items[i].ToString() == session.Id.ToString())
{
inThere = true;
}
}
}

if (inThere == false)
{
VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Add(session.Id.ToString());
}
if (inThere == false)
{
VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Add(session.Id.ToString());
}

});
});
}
catch (Exception ex) {
OutputText.outputLog("MediaManager_OnAnySessionOpened Exception: " + ex.Message, Color.Red);
}




}
private static void MediaManager_OnAnySessionClosed(MediaManager.MediaSession session)
{
string info = "[Windows Media Removed Source: " + session.Id + "]";
// var ot = new OutputText();
Task.Run(() => OutputText.outputLog(info));
VoiceWizardWindow.MainFormGlobal.Invoke((MethodInvoker)delegate ()
try
{
// VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Remove(session.Id.ToString());
});
}
string info = "[Windows Media Removed Source: " + session.Id + "]";
// var ot = new OutputText();
Task.Run(() => OutputText.outputLog(info));
VoiceWizardWindow.MainFormGlobal.Invoke((MethodInvoker)delegate ()
{
// VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.Items.Remove(session.Id.ToString());
});

}
catch (Exception ex) {
OutputText.outputLog("MediaManager_OnAnySessionClosed Exception: " + ex.Message, Color.Red);
}
}

private static void MediaManager_OnAnyPlaybackStateChanged(MediaManager.MediaSession sender, GlobalSystemMediaTransportControlsSessionPlaybackInfo args)
{
try {
if (approvedMediaSourceList.Contains(sender.Id.ToString()) == true)
{
string info = $"[{sender.Id} is now {args.PlaybackStatus}]"; //use this info to disable media output perioidically like the spotify feature. (like spotifyPause and heartratePause)
Expand All @@ -183,7 +204,13 @@ private static void MediaManager_OnAnyPlaybackStateChanged(MediaManager.MediaSes
mediaStatus = args.PlaybackStatus.ToString();
// Task.Run(() => VoiceWizardWindow.MainFormGlobal.ot.outputLog(VoiceWizardWindow.MainFormGlobal, mediaStatus));
}
//must also make option to output when paused
//must also make option to output when paused
}
catch (Exception ex)
{
OutputText.outputLog("MediaManager_OnAnyPlaybackStateChanged Exception: " + ex.Message, Color.Red);
}


}

Expand All @@ -210,44 +237,52 @@ private static void MediaManager_OnAnyMediaPropertyChanged(MediaManager.MediaSes
// System.Diagnostics.Debug.WriteLine(trimmed);
// }
// System.Diagnostics.Debug.WriteLine(VoiceWizardWindow.approvedMediaSourceList.Count);
approvedMediaSourceList.Clear();
foreach (object Item in VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.CheckedItems)
{
approvedMediaSourceList.Add(Item.ToString());
System.Diagnostics.Debug.WriteLine(Item.ToString());
}

if (approvedMediaSourceList.Contains(sender.Id.ToString()) == true)
try
{
approvedMediaSourceList.Clear();
foreach (object Item in VoiceWizardWindow.MainFormGlobal.checkedListBoxApproved.CheckedItems)
{
approvedMediaSourceList.Add(Item.ToString());
System.Diagnostics.Debug.WriteLine(Item.ToString());
}

string info = $"[{sender.Id} is now playing {args.Title} {(string.IsNullOrEmpty(args.Artist) ? "" : $"by {args.Artist}")}]";
// var ot = new OutputText();
if (args.Title != previousTitle && VoiceWizardWindow.MainFormGlobal.rjToggleButtonSpotifySpam.Checked == true && VoiceWizardWindow.MainFormGlobal.rjToggleButton10.Checked == true)
if (approvedMediaSourceList.Contains(sender.Id.ToString()) == true)
{

Task.Run(() => OutputText.outputLog(info));
string info = $"[{sender.Id} is now playing {args.Title} {(string.IsNullOrEmpty(args.Artist) ? "" : $"by {args.Artist}")}]";
// var ot = new OutputText();
if (args.Title != previousTitle && VoiceWizardWindow.MainFormGlobal.rjToggleButtonSpotifySpam.Checked == true && VoiceWizardWindow.MainFormGlobal.rjToggleButton10.Checked == true)
{

Task.Run(() => OutputText.outputLog(info));

}
if (args.Artist != null)
{
mediaTitle = args.Title;
mediaArtist = args.Artist;
mediaSource = sender.Id;
//mediaStatus = "Playing";

}
if (args.Artist != null)
{
mediaTitle = args.Title;
mediaArtist = args.Artist;
mediaSource = sender.Id;
//mediaStatus = "Playing";

}
if (args.Title != previousTitle)
{
var sp = new SpotifyAddon();
Task.Run(() => SpotifyAddon.windowsMediaGetSongInfo());
}
previousTitle = args.Title;

}
if (args.Title != previousTitle)
{
var sp = new SpotifyAddon();
Task.Run(() => SpotifyAddon.windowsMediaGetSongInfo());
}
previousTitle = args.Title;

}

}
catch (Exception ex)
{
OutputText.outputLog("MediaManager_OnAnyMediaPropertyChanged Exception: " + ex.Message, Color.Red);
}

}
}
}


Expand Down
23 changes: 18 additions & 5 deletions OSCVRCWiz/VoiceWizardWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace OSCVRCWiz

public partial class VoiceWizardWindow : Form
{
public static string currentVersion = "1.0.3.5";
public static string currentVersion = "1.0.3.6";
string releaseDate = "March 6, 2023";
string versionBuild = "x64"; //update when converting to x86/x64
//string versionBuild = "x86"; //update when converting to x86/x64
Expand Down Expand Up @@ -1083,10 +1083,23 @@ private void doToastTimerTick()

private void doWhisperTimerTick()
{
string text = WhisperRecognition.WhisperString;

VoiceWizardWindow.MainFormGlobal.MainDoTTS(text, "Whisper");
WhisperRecognition.WhisperString = "";

string text = WhisperRecognition.WhisperString;

// if (WhisperRecognition.WhisperString != WhisperRecognition.WhisperPrevText)
// {

VoiceWizardWindow.MainFormGlobal.MainDoTTS(text, "Whisper");

WhisperRecognition.WhisperPrevText = WhisperRecognition.WhisperString;
WhisperRecognition.WhisperString = "";
// }
// else
// {
// OutputText.outputLog("Whisper (FILTERED REPEAT): " + text);
// WhisperRecognition.WhisperPrevText = WhisperRecognition.WhisperString;
// WhisperRecognition.WhisperString = "";
// }



Expand Down

0 comments on commit 8766491

Please sign in to comment.