Skip to content

About

Native Swift SDK for the liberika media engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

中文 | English | 日本語

liberika for Swift

Native Swift SDK for the liberika media engine. It provides a Swift API and Metal-backed views for macOS, iOS, and tvOS. The prebuilt native runtime is downloaded automatically by Swift Package Manager; applications do not need Rust, FFmpeg, CocoaPods, or Flutter.

Requirements

  • macOS 11 or later
  • iOS 13 or later
  • tvOS 13 or later
  • Xcode 15 or later

Installation

In Xcode, choose File > Add Package Dependencies and enter:

https://github.com/AimesSoft/liberika-swift

Select version 0.3.6 or later and add the Erika product to your target.

UIKit / AppKit

import Erika

let player = try ErikaPlayer()
let videoView = ErikaVideoView(frame: container.bounds)
videoView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
videoView.player = player
container.addSubview(videoView)

try player.open("https://example.com/video.mp4")
try player.play()

ErikaVideoView owns a CAMetalLayer, keeps its drawable size synchronized with the native view, and drives the presenter's render loop.

SwiftUI

import Erika
import SwiftUI

struct PlayerScreen: View {
    let player: ErikaPlayer

    var body: some View {
        ErikaPlayerView(player: player)
            .task {
                try? player.open("https://example.com/video.mp4")
                try? player.play()
            }
    }
}

Create and use ErikaPlayer on the main actor. Poll pollEvent() for playback, position, buffering, track, decoder, and output changes. .ended follows the stopped state after natural completion; an explicit stop does not emit it.

Available APIs

  • open local files and HTTP(S) streams with custom headers and read-ahead control
  • play, pause, stop, seek, playback rate, and volume
  • audio and subtitle track discovery, selection, and bitrate/frame-rate metadata
  • external subtitles, subtitle scaling/style, and in-memory font registration
  • Bilibili XML / JSON danmaku tracks, offsets, filtering, and layout configuration
  • SDR, Apple EDR, extended-linear, and automatic output modes
  • packed-alpha output and ArtCNN, Anime4K, FSR 1.0, platform video, MetalFX, and custom upscaling modes
  • playback, decoder, output, upscaler, and resource statistics
  • composited RGBA frame capture
  • UIKit, AppKit, and SwiftUI video views

ErikaUpscaler selects the same numeric modes as the native SDK. Availability depends on the platform, input and device; inspect upscalerStatus() for the active backend and fallback. For a custom model, first call invoke("loadUpscalerModelFile", arguments: ["path": modelPath]), then select .custom with setUpscaler. The host must supply the .esr file or supported FSRCNNX / Anime4K CNN mpv hook shader; external model weights are not bundled. Use invoke("clearUpscalerModel") to unload it.

The lower-level invoke(_:arguments:) API also exposes other presenter commands without requiring an immediate Swift wrapper update.

License

The Swift wrapper is available under MPL-2.0. The binary target includes liberika and statically linked native dependencies; see THIRD_PARTY_NOTICES.md and the liberika release notices for their licenses.

About

Native Swift SDK for the liberika media engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages