BetterPlayerController class Null safety

Class used to control overall Better Player behavior. Main class to change state of Better Player.


BetterPlayerController(BetterPlayerConfiguration betterPlayerConfiguration, {BetterPlayerPlaylistConfiguration? betterPlayerPlaylistConfiguration, BetterPlayerDataSource? betterPlayerDataSource})


betterPlayerAsmsAudioTrack → BetterPlayerAsmsAudioTrack?
Selected ASMS audio track
betterPlayerAsmsAudioTracks List<BetterPlayerAsmsAudioTrack>?
List of all possible audio tracks returned from ASMS stream
betterPlayerAsmsTrack → BetterPlayerAsmsTrack?
Currently selected player track. Used only for HLS / DASH.
betterPlayerAsmsTracks List<BetterPlayerAsmsTrack>
List of tracks available for current data source. Used only for HLS / DASH.
betterPlayerConfiguration BetterPlayerConfiguration
General configuration used in controller instance.
betterPlayerDataSource BetterPlayerDataSource?
Currently used data source in player.
betterPlayerGlobalKey GlobalKey<State<StatefulWidget>>?
Getter of the GlobalKey
betterPlayerPlaylistConfiguration BetterPlayerPlaylistConfiguration?
Playlist configuration used in controller instance.
betterPlayerSubtitlesSource BetterPlayerSubtitlesSource?
Currently used subtitles source.
betterPlayerSubtitlesSourceList List<BetterPlayerSubtitlesSource>
List of BetterPlayerSubtitlesSources.
controllerEventStream Stream<BetterPlayerControllerEvent>
Stream of internal controller events. Shouldn't be used inside app. For normal events, use eventListener.
controlsAlwaysVisible bool
Are controls always visible
controlsEnabled bool
Flag which determines if controls (UI interface) is shown. When false, UI won't be shown (show only player surface).
controlsVisibilityStream Stream<bool>
Stream which sends flag whenever visibility of controls changes
eventListener → (dynamic Function?(BetterPlayerEvent)?)
Defines a event listener where video player events will be send.
hasCurrentDataSourceStarted bool
Flag which determines whenever current data source has started.
hashCode int
The hash code for this object. [...]
read-only, inherited
isFullScreen bool
Flag used to store full screen mode state.
nextVideoTimeStreamController StreamController<int?>
Stream controller which emits next video time.
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
subtitlesLines List<BetterPlayerSubtitle>
Subtitles lines for current data source.
read / write
translations BetterPlayerTranslations
Currently used translations
read / write
videoPlayerController ↔ VideoPlayerController?
Instance of video player controller which is adapter used to communicate between flutter high level code and lower level native code.
read / write


addEventsListener(dynamic eventListener(BetterPlayerEvent)) → void
Add event listener which listens to player events.
cancelNextVideoTimer() → void
Cancel next video timer. Used in playlist. Do not use manually.
clearCache() Future<void>
Clear all cached data. Video player controller must be initialized to clear the cache.
disablePictureInPicture() Future<void>?
Disable Picture in Picture mode if it's enabled.
dispose({bool forceDispose = false}) → void
Dispose BetterPlayerController. When forceDispose parameter is true, then autoDispose parameter will be overridden and controller will be disposed (if it wasn't disposed before).
enablePictureInPicture(GlobalKey<State<StatefulWidget>> betterPlayerGlobalKey) Future<void>?
Enable Picture in Picture (PiP) mode. betterPlayerGlobalKey is required to open PiP mode in iOS. When device is not supported, PiP mode won't be open.
enterFullScreen() → void
Enables full screen mode in player. This will trigger route change.
exitFullScreen() → void
Disables full screen mode in player. This will trigger route change.
getAspectRatio() double?
Get aspect ratio used in current video. If aspect ratio is null, then aspect ratio from BetterPlayerConfiguration will be used. Otherwise _overriddenAspectRatio will be used.
isBuffering() bool?
Flag which determines whenever player is loading video data or not.
isLiveStream() bool
Flag which determines whenever player is playing live data source.
isPictureInPictureSupported() Future<bool>
Check if picture in picture mode is supported in this device.
isPlaying() bool?
Flag which determines whenever player is playing or not.
isVideoInitialized() bool?
Flag which determines whenever player data source has been initialized.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
onPlayerVisibilityChanged(double visibilityFraction) → void
Listener which handles state of player visibility. If player visibility is below 0.0 then video will be paused. When value is greater than 0, video will play again. If there's different handler of visibility then it will be used. If showNotification is set in data source or handleLifecycle is false then this logic will be ignored.
pause() Future<void>
Stop video playback.
play() Future<void>
Start video playback. Play will be triggered only if current lifecycle state is resumed.
playNextVideo() → void
Play next video form playlist. Do not use manually.
postEvent(BetterPlayerEvent betterPlayerEvent) → void
Send player event. Shouldn't be used manually.
preCache(BetterPlayerDataSource betterPlayerDataSource) Future<void>
PreCache a video. Currently supports Android only. The future succeed when the requested size, specified in BetterPlayerCacheConfiguration.preCacheSize, is downloaded or when the complete file is downloaded if the file is smaller than the requested size.
removeEventsListener(dynamic eventListener(BetterPlayerEvent)) → void
Remove event listener. This method should be called once you're disposing Better Player.
retryDataSource() Future
Retry data source if playback failed.
seekTo(Duration moment) Future<void>
Move player to specific position/moment of the video.
setAppLifecycleState(AppLifecycleState appLifecycleState) → void
Set current lifecycle state. If state is AppLifecycleState.resumed then player starts playing again. if lifecycle is in AppLifecycleState.paused state, then video playback will stop. If showNotification is set in data source or handleLifecycle is false then this logic will be ignored.
setAudioTrack(BetterPlayerAsmsAudioTrack audioTrack) → void
Set audioTrack in player. Works only for HLS or DASH streams.
setBetterPlayerGlobalKey(GlobalKey<State<StatefulWidget>> betterPlayerGlobalKey) → void
Set GlobalKey of BetterPlayer. Used in PiP methods called from controls.
setControlsAlwaysVisible(bool controlsAlwaysVisible) → void
Setup controls always visible mode
setControlsEnabled(bool enabled) → void
Enable/disable controls (when enabled = false, controls will be always hidden)
setControlsVisibility(bool isVisible) → void
Show or hide controls manually
setLooping(bool looping) Future<void>
Enables/disables looping (infinity playback) mode.
setMixWithOthers(bool mixWithOthers) → void
Enable or disable audio mixing with other sound within device.
setOverriddenAspectRatio(double aspectRatio) → void
Setup overridden aspect ratio.
setResolution(String url) → void
Set different resolution (quality) for video
setSpeed(double speed) Future<void>
Set playback speed of video. Allows to set speed value between 0 and 2.
setTrack(BetterPlayerAsmsTrack track) → void
Setup track parameters for currently played video. Can be only used for HLS or DASH data source.
setupDataSource(BetterPlayerDataSource betterPlayerDataSource) Future
Setup new data source in Better Player.
setupSubtitleSource(BetterPlayerSubtitlesSource subtitlesSource, {bool sourceInitialize = false}) Future<void>
Setup subtitles to be displayed from given subtitle source. If subtitles source is segmented then don't load videos at start. Videos will load with just in time policy.
setupTranslations(Locale locale) → void
Setup translations for given locale. In normal use cases it shouldn't be called manually.
setVolume(double volume) Future<void>
Set volume of player. Allows values from 0.0 to 1.0.
startNextVideoTimer() → void
Start timer which will trigger next video. Used in playlist. Do not use manually.
stopPreCache(BetterPlayerDataSource betterPlayerDataSource) Future<void>
Stop pre cache for given betterPlayerDataSource. If there was no pre cache started for given betterPlayerDataSource then it will be ignored.
toggleControlsVisibility(bool isVisible) → void
Internal method, used to trigger CONTROLS_VISIBLE or CONTROLS_HIDDEN event once controls state changed.
toggleFullScreen() → void
Enables/disables full screen mode based on current fullscreen state.
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]

Static Methods

of(BuildContext context) BetterPlayerController
Get BetterPlayerController from context. Used in InheritedWidget.