Recently, LocalCast has stopped working on my Android devices - and that's a pain, because I no longer have a DVD player hooked to my TV (in fact, the only DVD player in the house is inside my PC) and all my videos are now stored on my RAID 5 NAS box. When LocalCast stops working, I can't easily watch videos, which understandably upsets Herself.
Chrome supports direct casting of webpages to a suitable device (such as Chromecast) so all I have to do is open the file in Chrome, cast it, and make it full page. It's a little clumsy, as the video controls are very basic, but it works. All I needed to do was automate the process of loading a non-page based file into Chrome.
And that's easy: change the file system based path to a
Uri and paste that into the address bar. Chrome opens the file, and off you go.
But ... that's complicated for Herself, so I wrote a quick program (that runs on my Win10 tablet, the WookieTab) that shows what videos are available, and shows them. She can learn to cast it ... I hope.
But this works for any file type, not just videos.
Using the Code
First off, we need to get the path to the default browser (as it may not be Chrome) - that's in the Registry, under HTTP associations:
private static string GetPathToDefaultBrowser()
const string currentUserSubKey =
using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(currentUserSubKey, false))
string progId = (userChoiceKey.GetValue("ProgId").ToString());
using (RegistryKey kp =
Registry.ClassesRoot.OpenSubKey(progId + @"\shell\open\command", false))
string rawValue = (string) kp.GetValue("");
Regex reg = new Regex("(?<=\").*?(?=\")");
Match m = reg.Match(rawValue);
return m.Success ? m.Value : "";
Then generate a
Uri from the file system path:
Uri uri = new System.Uri(filePath);
string converted = uri.AbsoluteUri;
And finally, open the file:
string browserPath = GetPathToDefaultBrowser();
- 2019-01-09: First version
- 2019-01-09: Tidier code in
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?