---
title: Mobile apps
description: "Apps show the player in a WebView: WKWebView on iOS, WebView on Android, or a framework's wrapper around them, such as React Native's or Flutter's."
---

The player in the WebView is the same one your website uses, with the same controls and behavior.

## Choose an approach

| Approach                    | What the WebView loads                                           | Site integration | Choose it when                                                                            |
| --------------------------- | ---------------------------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------- |
| **Open the embed directly** | `https://player.spinectrl.com/embed/<embedId>?channel=<channel>` | direct           | The player is all the WebView shows. Simplest, and needs no web page of your own.         |
| **Load a page of yours**    | a page on your own `https` website that embeds the player        | iframe or script | You want your own HTML around the player in the same WebView, such as race cards or odds. |

**For the direct approach,** ask Spine for a site with the _direct_ integration. It has no origins, and no web page can frame it: it's meant to be opened as a page of its own. Its embed URL takes the same `channel` and `channels` as an iframe's (see [the embed URL](/iframe#the-embed-url)), and the same [player settings](/iframe#player-settings-on-the-url). Leave out `channel` to play the site's default channel, and add `channels=1` to let viewers switch channels in the player, where Spine allows it.

**For a page of yours,** your app's WebView loads a page from your website, and that page embeds the player with an [iframe](/iframe) or the [hosted script](/hosted-script). The page's origin must be registered for its site, exactly as for a website. A separate site for the app lets Spine tell its viewers apart from your website's.

**What isn't supported**

- **HTML bundled in your app**, loaded from `file://`, `capacitor://localhost`, `ionic://localhost` or a local server inside the app. Spine can only allow real `https` origins, so the player refuses these pages. Load the embed directly, or a page from your website, instead.
- **Your app's own video player** (AVPlayer, ExoPlayer, Media3) playing Spine's streams. There's no API yet for an app to get the stream addresses. If you need it, talk to Spine.

## WebView settings the player needs

Whichever approach you choose, the WebView has to allow these. Without them the player can't autoplay, or plays only in the system's fullscreen player.

| Platform  | Setting                                                                    | Why                                                            |
| --------- | -------------------------------------------------------------------------- | -------------------------------------------------------------- |
| iOS       | `allowsInlineMediaPlayback = true`                                         | Play inside the page rather than taking over the screen.       |
| iOS       | `mediaTypesRequiringUserActionForPlayback = []`                            | Autoplay without a tap.                                        |
| iOS 15.4+ | `preferences.isElementFullscreenEnabled = true`                            | Let the player's fullscreen button work where iOS supports it. |
| Android   | `javaScriptEnabled = true`, `domStorageEnabled = true`                     | The player is a web app.                                       |
| Android   | `mediaPlaybackRequiresUserGesture = false`                                 | Autoplay without a tap.                                        |
| Android   | a `WebChromeClient` that handles `onShowCustomView` and `onHideCustomView` | Fullscreen.                                                    |

The player starts muted and shows "Tap to unmute", as in a browser.

## Examples by stack

**iOS**

With UIKit:

```swift
import UIKit
import WebKit

final class LivePlayerViewController: UIViewController {
    private let embedId = "01jdm8q3vz5k7r2x9c4n6b8t0w"
    private let channel: String? = "spor-1" // nil plays the site's default channel
    private var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .black

        let configuration = WKWebViewConfiguration()
        configuration.allowsInlineMediaPlayback = true
        configuration.mediaTypesRequiringUserActionForPlayback = []
        if #available(iOS 15.4, *) {
            configuration.preferences.isElementFullscreenEnabled = true
        }

        webView = WKWebView(frame: view.bounds, configuration: configuration)
        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        webView.isOpaque = false
        webView.backgroundColor = .black
        webView.scrollView.isScrollEnabled = false
        view.addSubview(webView)

        webView.load(URLRequest(url: Self.embedURL(embedId: embedId, channel: channel)))
    }

    static func embedURL(embedId: String, channel: String?) -> URL {
        var components = URLComponents()
        components.scheme = "https"
        components.host = "player.spinectrl.com"
        components.path = "/embed/\(embedId)"
        components.queryItems = channel.map { [URLQueryItem(name: "channel", value: $0)] }
        return components.url!
    }
}
```

With SwiftUI:

```swift
import SwiftUI
import WebKit

struct LivePlayerView: UIViewRepresentable {
    let embedId: String
    var channel: String? = nil // nil plays the site's default channel

    func makeUIView(context: Context) -> WKWebView {
        let configuration = WKWebViewConfiguration()
        configuration.allowsInlineMediaPlayback = true
        configuration.mediaTypesRequiringUserActionForPlayback = []
        if #available(iOS 15.4, *) {
            configuration.preferences.isElementFullscreenEnabled = true
        }
        let webView = WKWebView(frame: .zero, configuration: configuration)
        webView.isOpaque = false
        webView.backgroundColor = .black
        webView.scrollView.isScrollEnabled = false
        return webView
    }

    func updateUIView(_ webView: WKWebView, context: Context) {
        var components = URLComponents()
        components.scheme = "https"
        components.host = "player.spinectrl.com"
        components.path = "/embed/\(embedId)"
        components.queryItems = channel.map { [URLQueryItem(name: "channel", value: $0)] }
        guard let url = components.url, webView.url != url else { return }
        webView.load(URLRequest(url: url))
    }
}

// Usage:
// LivePlayerView(embedId: "01jdm8q3vz5k7r2x9c4n6b8t0w", channel: "spor-1")
//     .aspectRatio(16 / 9, contentMode: .fit)
```

To play sound while the phone's silent switch is on, set your app's audio session category to `.playback`, as for any video app.

**Android**

In an activity:

```kotlin
import android.annotation.SuppressLint
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity

class LivePlayerActivity : AppCompatActivity() {
    private lateinit var webView: WebView
    private var fullscreenView: View? = null

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        webView = WebView(this)
        setContentView(webView)

        webView.settings.javaScriptEnabled = true
        webView.settings.domStorageEnabled = true
        webView.settings.mediaPlaybackRequiresUserGesture = false
        webView.setBackgroundColor(android.graphics.Color.BLACK)

        webView.webChromeClient = object : WebChromeClient() {
            override fun onShowCustomView(view: View, callback: CustomViewCallback) {
                fullscreenView = view
                (window.decorView as FrameLayout).addView(
                    view,
                    FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT),
                )
                webView.visibility = View.GONE
            }

            override fun onHideCustomView() {
                (window.decorView as FrameLayout).removeView(fullscreenView)
                fullscreenView = null
                webView.visibility = View.VISIBLE
            }
        }

        webView.loadUrl(embedUrl(EMBED_ID, CHANNEL))
    }

    override fun onPause() {
        webView.onPause()
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
        webView.onResume()
    }

    override fun onDestroy() {
        webView.destroy()
        super.onDestroy()
    }

    companion object {
        const val EMBED_ID = "01jdm8q3vz5k7r2x9c4n6b8t0w"
        const val CHANNEL = "spor-1"

        // channel is the channel's slug or ID, or null for the site's default channel.
        fun embedUrl(embedId: String, channel: String?): String =
            Uri.Builder()
                .scheme("https")
                .authority("player.spinectrl.com")
                .appendPath("embed")
                .appendPath(embedId)
                .apply { if (channel != null) appendQueryParameter("channel", channel) }
                .build()
                .toString()
    }
}
```

In `AndroidManifest.xml`, the app needs the internet permission, and the activity should keep the WebView across rotation rather than reload it:

```xml
<uses-permission android:name="android.permission.INTERNET" />

<activity
    android:name=".LivePlayerActivity"
    android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" />
```

With Jetpack Compose:

```kotlin
import android.annotation.SuppressLint
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun LivePlayer(embedId: String, channel: String?, modifier: Modifier = Modifier) {
    val url = LivePlayerActivity.embedUrl(embedId, channel)
    AndroidView(
        modifier = modifier.fillMaxWidth().aspectRatio(16f / 9f),
        factory = { context ->
            WebView(context).apply {
                settings.javaScriptEnabled = true
                settings.domStorageEnabled = true
                settings.mediaPlaybackRequiresUserGesture = false
                webChromeClient = WebChromeClient()
                loadUrl(url)
            }
        },
        update = { webView -> if (webView.url != url) webView.loadUrl(url) },
        onRelease = { webView -> webView.destroy() },
    )
}
```

For fullscreen in Compose, give the `WebChromeClient` the same `onShowCustomView` and `onHideCustomView` as the activity above.

**React Native**

With [`react-native-webview`](https://github.com/react-native-webview/react-native-webview):

```tsx
import { StyleSheet, View } from "react-native";
import { WebView } from "react-native-webview";

const PLAYER_HOST = "https://player.spinectrl.com";

// `channel` is the channel's slug or ID. Left out, the site's default channel plays.
export function LivePlayer({ embedId, channel }: { embedId: string; channel?: string }) {
  const embed = `${PLAYER_HOST}/embed/${encodeURIComponent(embedId)}`;
  const uri = channel ? `${embed}?channel=${encodeURIComponent(channel)}` : embed;
  return (
    <View style={styles.frame}>
      <WebView
        source={{ uri }}
        allowsInlineMediaPlayback
        mediaPlaybackRequiresUserAction={false}
        allowsFullscreenVideo
        javaScriptEnabled
        domStorageEnabled
        scrollEnabled={false}
        style={styles.webView}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  frame: { width: "100%", aspectRatio: 16 / 9, backgroundColor: "#000" },
  webView: { flex: 1, backgroundColor: "#000" },
});
```

In Expo, install it with `npx expo install react-native-webview`.

**Flutter**

With [`webview_flutter`](https://pub.dev/packages/webview_flutter) 4 and its platform packages:

```dart
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

class LivePlayer extends StatefulWidget {
  const LivePlayer({super.key, required this.embedId, this.channel});

  final String embedId;

  /// The channel's slug or ID. Null plays the site's default channel.
  final String? channel;

  @override
  State<LivePlayer> createState() => _LivePlayerState();
}

class _LivePlayerState extends State<LivePlayer> {
  late final WebViewController _controller;

  @override
  void initState() {
    super.initState();

    PlatformWebViewControllerCreationParams params =
        const PlatformWebViewControllerCreationParams();
    if (WebViewPlatform.instance is WebKitWebViewPlatform) {
      params = WebKitWebViewControllerCreationParams(
        allowsInlineMediaPlayback: true,
        mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
      );
    }

    _controller = WebViewController.fromPlatformCreationParams(params)
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(Colors.black)
      ..loadRequest(Uri.https(
        'player.spinectrl.com',
        '/embed/${widget.embedId}',
        widget.channel == null ? null : {'channel': widget.channel!},
      ));

    final platform = _controller.platform;
    if (platform is AndroidWebViewController) {
      platform.setMediaPlaybackRequiresUserGesture(false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 16 / 9,
      child: WebViewWidget(controller: _controller),
    );
  }
}
```

## Protected playback

Which approach you choose decides which [protection levels](/security#protected-playback) the app's site can use:

- **Opening the embed directly** works at protection off and on player grants, and needs nothing more from your app. It can't use customer grants: no page of yours is there to hand the player a grant, so a direct site on customer grants plays nothing and shows "Your access to this stream couldn't be confirmed".
- **Loading a page of yours** works at every level. For customer grants, that page gets each viewer's grant from your backend, as your website does: with [`serveGrants`](/iframe#protected-playback) for an iframe, or [`getGrant`](/hosted-script#protected-playback) for the hosted script. Your backend has to know the viewer on that page, as on any private page of yours.

## Good to know

**Load a page of yours instead**

Point the WebView at your own page, and keep the same settings:

```swift
webView.load(URLRequest(url: URL(string: "https://www.example.com/app/live?channel=spor-1")!))
```

That page embeds the player with an [iframe](/iframe) or the [hosted script](/hosted-script), and its origin, `https://www.example.com` here, must be registered for its site. Everything on those pages applies, including the [referrer policy](/hosted-script#referrer-policy) for the hosted script.

**App lifecycle**

- **Background and foreground.** When your app goes to the background, the page is hidden. A muted player nobody listens to stops downloading after a few seconds, and starts again when the app comes back. On returning, the player checks Spine's schedule at once, so it never shows a stale state. On Android, call `webView.onPause()` and `onResume()` from your activity, as above.
- **Leaving the screen.** Destroy the WebView, or load `about:blank`, when the player's screen closes. That stops the stream.
- **Rotation.** Keep the WebView alive across rotation, so the stream doesn't restart. A WebView that fills the screen in landscape is the most reliable fullscreen on phones.

## Before you launch

Test on the devices and OS versions your audience uses: muted autoplay, unmuting, fullscreen and rotation, background and foreground, and switching between Wi-Fi and mobile data. WebView behavior differs between OS versions and between in-app browsers, and emulators don't reproduce all of it.

On a protected site, a partner's stream is signed for the viewer's internet address, so switching between Wi-Fi and mobile data may stop it for a moment before it recovers (see [Partner streams on protected sites](/security#partner-streams-on-protected-sites)).
