Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Android ExoPlayer

Improve this doc

Cordova media player plugin using Google's ExoPlayer framework.

https://github.com/google/ExoPlayer

Repo: https://github.com/frontyard/cordova-plugin-exoplayer

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-exoplayer
    $ npm install --save @ionic-native/android-exoplayer@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { AndroidExoPlayer } from '@ionic-native/android-exoplayer';

constructor(private androidExoPlayer: AndroidExoPlayer) { }

...

this.androidExoPlayer.show({url: 'http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube'});

Instance Members

show(parameters)

Show the player.

Param Type Details
parameters AndroidExoPlayerParams

Parameters

Returns: Observable<AndroidExoplayerState>

setStream(url, controller)

Switch stream without disposing of the player.

Param Type Details
url string

The url of the new stream.

controller AndroidExoPlayerControllerConfig

Configuration of the controller.

Returns: Promise<void>

playPause()

Will pause if playing and play if paused

Returns: Promise<void>

stop()

Stop playing.

Returns: Promise<void>

seekTo(milliseconds)

Jump to a particular position.

Param Type Details
milliseconds number

Position in stream in milliseconds

Returns: Promise<void>

seekBy(milliseconds)

Jump to a particular time relative to the current position.

Param Type Details
milliseconds number

Time in milliseconds

Returns: Promise<void>

getState()

Get the current player state.

Returns: Promise<AndroidExoplayerState>

showController()

Show the controller.

Returns: Promise<void>

hideController()

Hide the controller.

Returns: Promise<void>

setController(controller)

Update the controller configuration.

Param Type Details
controller AndroidExoPlayerControllerConfig

Configuration of the controller.

Returns: Promise<void>

close()

Close and dispose of player, call before destroy.

Returns: Promise<void>

AndroidExoPlayerParams

Param Type Details
url string

Url of the video to play.

userAgent string

Set the user agent. Default is ExoPlayerPlugin

(optional)
aspectRatio AndroidExoPlayerAspectRatio

Set the player aspect ratio.

(optional)
hideTimeout number

Hide controls after this many milliseconds, default is 5000.

(optional)
autoPlay boolean

When set to false stream will not automatically start.

(optional)
seekTo number

Start playback at this many milliseconds into video, default is 0.

(optional)
forwardTime number

Amount of time in milliseconds to use when skipping forward, default is 1000.

(optional)
rewindTime number

Amount of time in milliseconds to use when skipping backward, default is 1000.

(optional)
audioOnly

Only play audio in the backgroud, default is false. If you pass in audioOnly: true, make sure to manually close the player on some event (like escape button) since the plugin won't be detecting keypresses when playing audio in the background.

(optional)
true
subtitleUrl string

Optional subtitle url to display over the video. We currently support .srt and .vtt subtitle formats. Subtitles are not supported on all stream types, as ExoPlayer has requirement that both video and subtitle "must have the same number of periods, and must not have any dynamic windows", which means for simple mp4s it should work, but on more complex HLS/Dash setups it might not.

(optional)
connectTimeout number

okhttp connect timeout in milliseconds (default is 0)

(optional)
readTimeout number

okhttp read timeout in milliseconds (default is 0)

(optional)
writeTimeout number

okhttp write timeout in milliseconds (default is 0)

(optional)
pingInterval number

okhttp socket ping interval in milliseconds (default is 0 or disabled)

(optional)
retryCount number

Number of times datasource will retry the stream before giving up (default is 3)

(optional)
controller AndroidExoPlayerControllerConfig

If this object is not present controller will not be visible.

(optional)

AndroidExoplayerState

Param Type Details

AndroidExoPlayerControllerConfig

Param Type Details
streamImage string

Image in the controller.

streamTitle string
streamDescription string
hideProgress

Hide entire progress bar.

(optional)
true
hidePosition

If progress bar is visible hide current position from it

false
hideDuration

If progress bar is visible Hide stream duration from it

controlIcons */ exo_ffwd: string; }

Override the player control button icons.

(optional)

API

Native

General