3rd-party App Integration

Overview

Developers of third-party apps and services can take advantage of VidHub's video playback capabilities and play videos using URL schemes. It also supports x-callback, allowing to return to another app after the operation is completed.
Available platforms: iPhone, iPad

Usage Examples

Play a single file and return to another application when finished

open-vidhub://x-callback-url/open?
on-success=some-app://x-callback-url/success&
on-failed=some-app://x-callback-url/failed&
url=http://localhost:8080/sample.mp4

Play a single file with external subtitles added

open-vidhub://x-callback-url/open?
on-success=some-app://x-callback-url/success&
on-failed=some-app://x-callback-url/failed&
url=http://localhost:8080/sample.mp4&
sub=http://localhost:8080/sample.srt

URL Encoding

All query string values ​​should be URL-encoded per the x-callback-url specification. Unencoded URLs may work in some cases, but you may need to manually URL-encode when using actions with multiple parameters or URLs with multiple keys.

Original URL

http://localhost:8080/Movies/movie.mkv

Encoded URL

http%3A%2F%2Flocalhost%3A8080%2Fsample.mp4

3rd-party integration examples

Third-party applications can call this method to pass video files or subtitles to VidHub for playback.

func openWithVidHub(url: URL, subUrl: URL? = nil) {
    let urlString = url.isFileURL ? url.path.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) : url.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
    // Create with URLComponents
    var components = URLComponents()
    components.scheme = "open-vidhub"
    components.host = "x-callback-url"
    components.path = "/open"
    var queryItems: [URLQueryItem] = [URLQueryItem]()
    queryItems.append(URLQueryItem(name: "url", value: urlString))
    
    // subtitles, optional
    if let subUrl = subUrl, 
        let subUrlString = subUrl.isFileURL ? subUrl.path.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) : subUrl.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
      queryItems.append(URLQueryItem(name: "sub", value: subUrlString))
    }
    
    // Optionally, you can also add callback urls in queryItems
    queryItems.append(URLQueryItem(name: "on-success", value: "mySchema://x-callback-url/success".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)))
    queryItems.append(URLQueryItem(name: "on-failed", value: "mySchema://x-callback-url/failed".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)))
    
    components.queryItems = queryItems
    
    guard let vidHubURL = components.url else {
      return
    }

    debugPrint("Open with VidHub: \(vidHubURL.absoluteString)")

    UIApplication.shared.open(vidHubURL, options: [:], completionHandler: nil)
  } 

You can also call scene(_:openURLContexts:) to handle callback methods from VidHub.

  func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
      return
    }
    // Process api call from VidHub
    // mySchema://x-callbacksw-url/success or mySchema://x-callback-url/failed
    if url.scheme == "mySchema" {
      if url.host == "x-callback-url" {
        if url.path == "/success" {
          // Handle success
          debugPrint("Success")
        } else if url.path == "/failed" {
          // Handle failed
          debugPrint("Failed")
        }
      }
    }    
  }