Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cellularmitosis committed Jul 24, 2023
1 parent 7833b14 commit 8e8bde9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Binary file added .media/open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
# VLCFileUrl
Open vlc-file://foo with VLC as http://foo.

Open `vlc-file://foo` with VLC as `http://foo`.

![](.media/open.png)


## Rationale

So you're building a simple webapp to play video files (i.e. a minimal DIY plex-like media server).

The HTML5 [`<video>`](https://en.wikipedia.org/wiki/HTML5_video) tag can natively stream `.mp4` files, `.webm` files, etc.

But what about other types of video files, like `.mkv`? Unfortunately, there's no good way to do this in the browser.

[VLC](https://www.videolan.org/vlc/) can play `.mkv` files, but downloading the file first isn't convenient -- we want to _stream_ it. VLC can also stream `.mkv` URLs, but how to we get the browser to hand off the URL to VLC (without downloading the file)?

This is the problem. There's no way to tell your browser that an `http://` URL to a specific type of file should be handled by an external application.

But if we invent our own URL scheme, we can register an external application to handle it natively. That's what this app is for.

This app registers the URL scheme `vlc-file://`, rewrites those URLs as `http://` and hands them off to VLC for streaming.


## Simple

This is the simplest possible app which can do this. No joke, here's the entirety of the source code:

```swift
import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet var window: NSWindow!

func application(_ application: NSApplication, open urls: [URL]) {
for url in urls {
let httpUrlString = url.absoluteString.replacingOccurrences(
of: "vlc-file://",
with: "http://"
)
let job = Process()
job.executableURL = URL(fileURLWithPath: "/usr/bin/open")
job.arguments = ["-a", "VLC", httpUrlString]
try? job.run()
job.waitUntilExit()
}
NSApp.terminate(self)
}
}
```


## License

[MIT](https://opensource.org/license/mit/), baby 😎.

0 comments on commit 8e8bde9

Please sign in to comment.