logo
IntroductionHow to add CSS or JavaScript files to an Android/iOS projectHow to combat autoplay policiesWhy does fullscreen not behave as expected on iOSWhy does the Network API not work on iOS devicesWhy does Chromecast not work on iOS Chrome?Why can't I select another video quality on iOS/tvOS?Is YouTube supportedWhy does the player load only one audio track (even though there are several in the manifest)Is it possible to see 360 degrees photo with THEOplayerWhy the Visibility API does not work through an iframe on Safari and IE11What is an impressionHow to know whether a live stream is playingWhich error related events does the player exposeWhy did my subtitles stop workingHow does Media Engagement Index (MEI) affect Autoplay on ChromeWhat does the error message 'Unknown CDM error' meanWhat does the error message 'Something went wrong with Native playback' meanWhy are not all response headers exposedWhy does the currentTime seem off in my livestream & what can I do about itHow to remove CORS restrictions from a reproduction streamWhich network calls (or requests) does THEOplayer doWhy does the playback not work when using the Chrome iPhone/iPad simulatorWhat does the error message 'can only be initiated by a user gesture' imply? Can I still force the desired actionHow to remove unwanted CC track in iOS or SafariWhy do I get a gray play button in my Android WebView and how to remove it?MediaTek limitationsHow to use ProGuard with THEOplayer Android SDKSelf-hosting and versioning of THEOplayerDoes THEOplayer support EXT-X-DATERANGECan clipping be used on a playlistCan timeline thumbnails be made available before playback startWhat are the benefits of preloadingWhat are the player seeking and seeked events and when are they firedCan we use HLS or DASH adsHow to change text in THEOplayerChange text when AirplayingITP2.1 problems using THEOplayerRemoving context menu/'Powered by THEOplayer v2...'What aspects of THEOplayer do we need to take into account to deploy a proper Content Security Policy (CSP)How can we avoid that the player keeps looking for chunks/segments if they are not foundCan we show a custom message on 403 on mp4Can we prevent UpNext feature from redirectingIs it possible to preload VOD content while the pre-roll is playingWhy is my video not playing automaticallyIs it possible to have multiple player instances play at the same timeIs it a problem if the viewer pauses a live stream for longer than the DVR windowTHEOplayer Features & ModulesChromecast on my webplayer does not work any longer despite no change in my implementationHow to track network errorsWhat is the support for WowzaHow to use the CDN fallback/backup stream featureHow to apply accurate buffering strategyHow can I distribute 4K content?What is the collaboration between Azure Media Services and THEOplayerIs Portrait mode supportedHow to prevent screen recordingThe provided video source is incompatible with the license for this playerPage and Source domainsWhat does the error message “Something went wrong determining the initial period of the provided MPEG-DASH stream” meanWhy is my PlayReady stream not working in Chromium Edge?Which subtitle and CC formats are supported on native SafariHow to navigate through the documentation and resourcesHow to create a (great) ticketHow to investigate a ticketWhat are the limitations of AirPlayWhat are the Edgio challengesHow to use the Media Session APIHow to use THEOplayer iOS SDK on an M1 macWidevine CDM deprecation notice for old browser versions

How to add CSS or JavaScript files to an Android/iOS project

This guide describes how to add CSS or JavaScript files to an Android or iOS project, and manipulate the player using CSS and/or JavaScript.

Including these files allows you to create a hybrid application to increase code re-usability:

  • You can build a UI for Web, and re-use it in your Android or iOS application.
  • You can add JavaScript logic, and re-use it in your Android or iOS application.

Through JavaScript, you have access to some THEOplayer features which aren't exposed in the iOS or Android SDK, such as the Network API.

How to communicate with messages between your Android/iOS application, and your JavaScript logic, will be discussed in a follow-up article.

Pre-requirements

Android

Add or confirm you have an assets folder in your project. In Android Studio, if you do not have an assets directory, you can simply add it by right-clicking > new > folder > assets folder.

Add the JavaScript and/or CSS file

Legacy Android SDK (4.12.x)

You can drag and drop files into the assets directory, or right-click and create a new file.

The JavaScript file can directly refer to the player variable on which you can perform many actions, for example:

player.source = {
    "sources": {
    "src": "//cdn.theoplayer.com/video/elephants-dream/playlist.m3u8",
    "useCredentials": false
    }
}

Please note that it is not possible to inject JavaScript/CSS to Android SDK 5.0+ with this method.

iOS

You can Add Files to <YOUR_PROJECT> by right-clicking on your project to include new JavaScript or CSS files.

Please note that currently it is not possible to inject JavaScript/CSS when THEOplayer iOS SDK is chromeless.

Legacy Android SDK (4.12.x)

This can be done through XML:

<com.theoplayer.android.api.THEOplayerView
        android:id="@+id/theo_player_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultCss="true"
        app:cssPaths="path/to/style1.css" 
        app:jsPaths="path/to/script1.js" />

Or directly in the player config in Java:

THEOplayerConfig playerConfig = new THEOplayerConfig.Builder()
            .chromeless(false)
            .defaultCss(true)
            .cssPaths("path/to/style1.css","path/to/style2.css") // Path is relative to the location of the assets directory
            .jsPaths("path/to/script1.js","path/to/script2.js")
            .build();
THEOplayerView tpv = new THEOplayerView(this, playerConfig);

iOS

You can do this programmatically through Swift when initializing your THEOplayer instance.

let stylePath = Bundle.main.path(forResource:"style1", ofType: "css")! // style1.css
let scriptPath = Bundle.main.path(forResource:"script1", ofType: "js")! // script1.css
let playerConfig = THEOplayerConfiguration(license: "your_license_here", defaultCSS: true, cssPaths:[stylePath], jsPaths: [scriptPath])
self.theoplayer = THEOplayer(configuration: playerConfig)
github
Make sure to follow us on GitHub!
THEO-logo-white
twitter
facebook
linkedin
Copyright © 2022. All Rights Reserved.
Leuven
New York
Singapore
Barcelona