-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7833b14
commit 8e8bde9
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 😎. |