### Install Flutter Packages Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/install.md Command to execute after modifying pubspec.yaml to fetch and install project dependencies, including Better Player Plus. ```bash $ flutter pub get ``` -------------------------------- ### Basic Network Video Playback with Better Player Plus Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/README.md This example demonstrates the minimal setup for playing a network video using Better Player Plus. It involves creating a BetterPlayerDataSource with a network URL and a BetterPlayerController, then rendering the BetterPlayer widget. ```dart final dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', ); final controller = BetterPlayerController( const BetterPlayerConfiguration(), betterPlayerDataSource: dataSource, ); // In your widget tree BetterPlayer ( controller: controller ); ``` -------------------------------- ### Normal Better Player Setup with Controller (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/generalplayerusage.md Illustrates a more advanced setup for Better Player, involving explicit creation of `BetterPlayerDataSource` and `BetterPlayerController`. This approach provides greater flexibility for managing video sources, subtitles, and player behavior. It is typically implemented within the `initState` method of a StatefulWidget. ```dart BetterPlayerController _betterPlayerController; @override void initState() { super.initState(); BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"); _betterPlayerController = BetterPlayerController( BetterPlayerConfiguration(), betterPlayerDataSource: betterPlayerDataSource); } ``` ```dart @override Widget build(BuildContext context) { return AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer( controller: _betterPlayerController, ), ); } ``` -------------------------------- ### Basic Better Player Setup (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/generalplayerusage.md Demonstrates the simplest way to initialize and display a video using Better Player from a network URL. This method sets up default configurations, allowing for quick integration. It requires a valid video URL and optionally accepts a `BetterPlayerConfiguration` object. ```dart BetterPlayer.network(url, configuration) BetterPlayer.file(url, configuration) ``` ```dart @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Example player"), ), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer.network( "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4", betterPlayerConfiguration: BetterPlayerConfiguration( aspectRatio: 16 / 9, ), ), ), ); } ``` -------------------------------- ### Add Dependency to pubspec.yaml Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/install.md This snippet shows how to add the better_player dependency to your Flutter project's pubspec.yaml file. Ensure you use a compatible version. ```yaml dependencies: better_player: ^0.0.83 ``` -------------------------------- ### Setup Video with Resolutions in Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/resolutionsofvideo.md Demonstrates how to configure a BetterPlayerDataSource with multiple video resolutions. This is suitable for standard video files and allows users to choose between different quality options. It requires the Better Player Plus library. ```dart var dataSource = BetterPlayerDataSource(BetterPlayerDataSourceType.network, "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4", resolutions: { "LOW": "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4", "MEDIUM": "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4", "LARGE": "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1280_10MG.mp4", "EXTRA_LARGE": "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4" }); ``` -------------------------------- ### Configure Network Data Source with Subtitles and Headers Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/datasourceconfiguration.md Example of creating a network data source for Better Player Plus. This includes specifying the video URL, adding file-based subtitles, and setting custom HTTP headers for the request. It demonstrates the flexibility in configuring network streams. ```dart var dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4", subtitles: BetterPlayerSubtitlesSource( type: BetterPlayerSubtitlesSourceType.file, url: "${directory.path}/example_subtitles.srt", ), headers: {"header":"my_custom_header"} ); ``` -------------------------------- ### Import Better Player Plus in Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/install.md How to import the Better Player Plus library into your Dart files to start using its functionalities. This is a standard import statement for Flutter packages. ```dart import 'package:better_player_plus/better_player_plus.dart'; ``` -------------------------------- ### Configure Full-Screen Behavior with Better Player Plus (Dart) Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt This example demonstrates how to configure full-screen playback options for the Better Player Plus library. It includes settings for the default full-screen aspect ratio, automatic detection of device orientation and aspect ratio, and specifying allowed device orientations both during and after full-screen mode. It also controls system overlays and screen sleep behavior. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class FullScreenPlayerPage extends StatefulWidget { @override _FullScreenPlayerPageState createState() => _FullScreenPlayerPageState(); } class _FullScreenPlayerPageState extends State { late BetterPlayerController _controller; @override void initState() { super.initState(); _controller = BetterPlayerController( BetterPlayerConfiguration( aspectRatio: 16 / 9, fullScreenByDefault: false, fullScreenAspectRatio: 16 / 9, autoDetectFullscreenDeviceOrientation: true, autoDetectFullscreenAspectRatio: true, deviceOrientationsOnFullScreen: [ DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight, ], deviceOrientationsAfterFullScreen: [ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight, ], systemOverlaysAfterFullScreen: SystemUiOverlay.values, allowedScreenSleep: false, ), betterPlayerDataSource: BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", ), ); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Full Screen Player")), body: Column( children: [ AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer(controller: _controller), ), Padding( padding: EdgeInsets.all(16), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( onPressed: () => _controller.enterFullScreen(), child: Text("Enter Fullscreen"), ), ElevatedButton( onPressed: () => _controller.exitFullScreen(), child: Text("Exit Fullscreen"), ), ], ), ), ], ), ); } } ``` -------------------------------- ### ClearKey DRM XML Configuration Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/drmconfiguration.md Example XML structure for configuring ClearKey DRM using GPACDRM. This file defines encryption details for MP4 files. ```xml ``` -------------------------------- ### Dynamically Update Player Controls Configuration Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/controlsconfiguration.md This code example illustrates how to change the player's control configurations at runtime. It uses the setBetterPlayerControlsConfiguration method of BetterPlayerController to update specific settings, such as the overflow modal color. ```dart _betterPlayerController.setBetterPlayerControlsConfiguration( BetterPlayerControlsConfiguration( overflowModalColor: Colors.amberAccent), ); ``` -------------------------------- ### iOS Full Screen Rotation Configuration (info.plist) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/install.md XML snippet to add to your project's info.plist file to enable full-screen rotation support for Better Player. This allows the video player to rotate to landscape mode. ```xml UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight ``` -------------------------------- ### BetterPlayerBufferingConfiguration Options (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/bufferingconfiguration.md Details the parameters available for BetterPlayerBufferingConfiguration, allowing developers to control video buffering behavior. These include minimum and maximum buffer durations, and specific durations required for playback to start or resume after a rebuffer event. These configurations are crucial for optimizing video playback performance. ```dart ///The default minimum duration of media that the player will attempt to ///ensure is buffered at all times, in milliseconds. final int minBufferMs; ///The default maximum duration of media that the player will attempt to ///buffer, in milliseconds. final int maxBufferMs; ///The default duration of media that must be buffered for playback to start ///or resume following a user action such as a seek, in milliseconds. final int bufferForPlaybackMs; ///The default duration of media that must be buffered for playback to resume ///after a rebuffer, in milliseconds. A rebuffer is defined to be caused by ///buffer depletion rather than a user action. final int bufferForPlaybackAfterRebufferMs; ``` -------------------------------- ### Create Video Data Source List for Playlist (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/playlistplayerusage.md This Dart code snippet demonstrates how to create a list of `BetterPlayerDataSource` objects, which are required for the BetterPlayerPlaylist widget. It includes examples of network video sources and HLS streams. Ensure you have the Better Player library integrated into your project. ```dart List createDataSet() { List dataSourceList = List(); dataSourceList.add( BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4", ), ); dataSourceList.add( BetterPlayerDataSource(BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"), ); dataSourceList.add( BetterPlayerDataSource(BetterPlayerDataSourceType.network, "http://sample.vodobox.com/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8"), ); return dataSourceList; } ``` -------------------------------- ### Configure Video Buffering with Better Player Plus (Dart) Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt This snippet shows how to configure video buffering parameters for the Better Player Plus library. It allows setting minimum and maximum buffer durations in milliseconds, as well as buffer requirements for starting playback and after rebuffering. This is useful for optimizing video playback performance based on network conditions. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class BufferingConfigPlayerPage extends StatefulWidget { @override _BufferingConfigPlayerPageState createState() => _BufferingConfigPlayerPageState(); } class _BufferingConfigPlayerPageState extends State { late BetterPlayerController _controller; @override void initState() { super.initState(); BetterPlayerDataSource dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", bufferingConfiguration: BetterPlayerBufferingConfiguration( minBufferMs: 15000, // Minimum buffer before playback starts maxBufferMs: 50000, // Maximum buffer size bufferForPlaybackMs: 2500, // Buffer required to start playback bufferForPlaybackAfterRebufferMs: 5000, // Buffer after rebuffering ), ); _controller = BetterPlayerController( BetterPlayerConfiguration(aspectRatio: 16 / 9), betterPlayerDataSource: dataSource, ); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Buffering Config")), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer(controller: _controller), ), ); } } ``` -------------------------------- ### Initialize BetterPlayerConfiguration in Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/generalconfiguration.md This snippet demonstrates how to create a BetterPlayerConfiguration instance in Dart. It sets common options like autoPlay, looping, and fullScreenByDefault. This configuration object is used when initializing the BetterPlayerController. ```dart var betterPlayerConfiguration = BetterPlayerConfiguration( autoPlay: true, looping: true, fullScreenByDefault: true, ); ``` -------------------------------- ### Create Basic File Video Player Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt Shows how to play a video from a local file path using the BetterPlayer.file factory constructor. Requires a file path as input and allows configuration of player settings. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class BasicFilePlayerPage extends StatelessWidget { final String filePath; BasicFilePlayerPage({required this.filePath}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("File Video")), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer.file( filePath, // e.g., "/storage/emulated/0/Download/video.mp4" betterPlayerConfiguration: BetterPlayerConfiguration( aspectRatio: 16 / 9, ), ), ), ); } } ``` -------------------------------- ### Create Basic Network Video Player Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt Demonstrates the simplest way to play a video from a network URL using the BetterPlayer.network factory constructor. It configures aspect ratio, autoplay, and looping. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class BasicNetworkPlayerPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Network Video")), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer.network( "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", betterPlayerConfiguration: BetterPlayerConfiguration( aspectRatio: 16 / 9, autoPlay: false, looping: false, ), ), ), ); } } ``` -------------------------------- ### BetterPlayerDataSource Configuration Options Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/datasourceconfiguration.md A comprehensive list of configuration options available for BetterPlayerDataSource. These options allow fine-grained control over video playback, including source type, URLs, subtitles, live streaming, custom headers, HLS/DASH track management, alternative resolutions, caching, memory playback, notifications, duration overrides, video format hints, DRM, and placeholders. ```dart ///Type of source of video final BetterPlayerDataSourceType type; ///Url of the video final String url; ///Subtitles configuration ///You can pass here multiple subtitles final List subtitles; ///Flag to determine if current data source is live stream final bool liveStream; /// Custom headers for player final Map headers; ///Should player use hls / dash subtitles (ASMS - Adaptive Streaming Media Sources). final bool useAsmsSubtitles; ///Should player use hls / dash tracks final bool useAsmsTracks; ///Should player use hls / dash audio tracks final bool useAsmsAudioTracks; ///List of strings that represents tracks names. ///If empty, then better player will choose name based on track parameters final List hlsTrackNames; ///Optional, alternative resolutions for non-hls video. Used to setup ///different qualities for video. ///Data should be in given format: ///{"360p": "url", "540p": "url2" } final Map resolutions; ///Optional cache configuration, used only for network data sources final BetterPlayerCacheConfiguration cacheConfiguration; ///List of bytes, used only in memory player final List bytes; ///Configuration of remote controls notification final BetterPlayerNotificationConfiguration notificationConfiguration; ///Duration which will be returned instead of original duration final Duration overriddenDuration; ///Video format hint when data source url has not valid extension. final BetterPlayerVideoFormat videoFormat; ///Extension of video without dot. Used only in memory data source. final String videoExtension; ///Configuration of content protection final BetterPlayerDrmConfiguration drmConfiguration; ///Placeholder widget which will be shown until video load or play. This ///placeholder may be useful if you want to show placeholder before each video ///in playlist. Otherwise, you should use placeholder from /// BetterPlayerConfiguration. final Widget placeholder; ``` -------------------------------- ### BetterPlayerConfiguration Options in Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/generalconfiguration.md This section lists and describes the various configuration options available within the BetterPlayerConfiguration class. These options control aspects such as playback behavior, UI elements, error handling, and fullscreen behavior. ```dart /// Play the video as soon as it's displayed final bool autoPlay; /// Start video at a certain position final Duration startAt; /// Whether or not the video should loop final bool looping; /// Weather or not to show the controls when initializing the widget. final bool showControlsOnInitialize; /// When the video playback runs into an error, you can build a custom /// error message. final Widget Function(BuildContext context, String errorMessage) errorBuilder; /// The Aspect Ratio of the Video. Important to get the correct size of the /// video! /// /// Will fallback to fitting within the space allowed. final double aspectRatio; /// The placeholder is displayed underneath the Video before it is initialized /// or played. final Widget placeholder; /// Should the placeholder be shown until play is pressed final bool showPlaceholderUntilPlay; /// Placeholder position of player stack. If false, then placeholder will be /// displayed on the bottom, so user need to hide it manually. Default is /// true. final bool placeholderOnTop; /// A widget which is placed between the video and the controls final Widget overlay; /// Defines if the player will start in fullscreen when play is pressed final bool fullScreenByDefault; /// Defines if the player will sleep in fullscreen or not final bool allowedScreenSleep; /// Defines aspect ratio which will be used in fullscreen final double fullScreenAspectRatio; /// Defines the set of allowed device orientations on entering fullscreen final List deviceOrientationsOnFullScreen; /// Defines the system overlays visible after exiting fullscreen final List systemOverlaysAfterFullScreen; /// Defines the set of allowed device orientations after exiting fullscreen final List deviceOrientationsAfterFullScreen; /// Defines a custom RoutePageBuilder for the fullscreen final BetterPlayerRoutePageBuilder routePageBuilder; /// Defines a event listener where video player events will be send final Function(BetterPlayerEvent) eventListener; ///Defines subtitles configuration final BetterPlayerSubtitlesConfiguration subtitlesConfiguration; ///Defines controls configuration final BetterPlayerControlsConfiguration controlsConfiguration; ///Defines fit of the video, allows to fix video stretching, see possible ///values here: https://api.flutter.dev/flutter/painting/BoxFit-class.html final BoxFit fit; ///Defines rotation of the video in degrees. Default value is 0. Can be 0, 90, 180, 270. ///Angle will rotate only video box, controls will be in the same place. final double rotation; ///Defines function which will react on player visibility changed final Function(double visibilityFraction) playerVisibilityChangedBehavior; ///Defines translations used in player. If null, then default english translations ///will be used. final List translations; ///Defines if player should auto detect full screen device orientation based ///on aspect ratio of the video. If aspect ratio of the video is < 1 then ///video will played in full screen in portrait mode. If aspect ratio is >= 1 ///then video will be played horizontally. If this parameter is true, then ///[deviceOrientationsOnFullScreen] and [fullScreenAspectRatio] value will be /// ignored. final bool autoDetectFullscreenDeviceOrientation; ///Defines if player should auto detect full screen aspect ration of the video. ///If [deviceOrientationsOnFullScreen] is true this is done automaticaly also. final bool autoDetectFullscreenAspectRatio; ///Defines flag which enables/disables lifecycle handling (pause on app closed, ///play on app resumed). Default value is true. final bool handleLifecycle; ///Defines flag which enabled/disabled auto dispose on BetterPlayer dispose. ///Default value is true. final bool autoDispose; ///Flag which causes to player expand to fill all remaining space. Set to false ///to use minimum constraints final bool expandToFill; ///Flag which causes to player use the root navigator to open new pages. ///Default value is false. final bool useRootNavigator; ``` -------------------------------- ### Custom Video Player Controls Configuration in Flutter Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt Demonstrates how to customize the appearance and behavior of the video player controls using BetterPlayerControlsConfiguration. This includes setting colors, icons, visibility, and enabling/disabling various features like fullscreen, mute, and playback speed. It requires the 'better_player_plus' and 'flutter' packages. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class CustomControlsPlayerPage extends StatefulWidget { @override _CustomControlsPlayerPageState createState() => _CustomControlsPlayerPageState(); } class _CustomControlsPlayerPageState extends State { late BetterPlayerController _controller; @override void initState() { super.initState(); _controller = BetterPlayerController( BetterPlayerConfiguration( aspectRatio: 16 / 9, controlsConfiguration: BetterPlayerControlsConfiguration( // Colors controlBarColor: Colors.black87, textColor: Colors.white, iconsColor: Colors.white, progressBarPlayedColor: Colors.red, progressBarHandleColor: Colors.red, progressBarBufferedColor: Colors.white70, progressBarBackgroundColor: Colors.white30, loadingColor: Colors.red, backgroundColor: Colors.black, overflowModalColor: Colors.grey[900]!, overflowModalTextColor: Colors.white, // Controls visibility showControls: true, showControlsOnInitialize: true, controlsHideTime: Duration(seconds: 3), // Feature toggles enableFullscreen: true, enableMute: true, enableProgressBar: true, enableProgressBarDrag: true, enablePlayPause: true, enableSkips: true, enableOverflowMenu: true, enablePlaybackSpeed: true, enableSubtitles: true, enableQualities: true, enablePip: true, enableRetry: true, enableAudioTracks: true, // Skip times forwardSkipTimeInMilliseconds: 10000, backwardSkipTimeInMilliseconds: 10000, // Control bar controlBarHeight: 48.0, ), ), betterPlayerDataSource: BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", ), ); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Custom Controls")), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer(controller: _controller), ), ); } } ``` -------------------------------- ### Configure Subtitle Appearance with BetterPlayerSubtitlesConfiguration Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/subtitlesconfiguration.md Demonstrates how to customize the visual appearance of subtitles using BetterPlayerSubtitlesConfiguration. This includes settings for font size, color, outline, and padding. ```dart var betterPlayerConfiguration = BetterPlayerConfiguration( subtitlesConfiguration: BetterPlayerSubtitlesConfiguration( fontSize: 20, fontColor: Colors.green, ), ); ``` -------------------------------- ### Better Player Widget with GlobalKey (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/pictureinpictureconfiguration.md Demonstrates how to integrate the BetterPlayer widget with a GlobalKey, which is necessary for enabling Picture in Picture mode. The AspectRatio widget ensures the video maintains its intended aspect ratio. ```dart GlobalKey _betterPlayerKey = GlobalKey(); ... AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer( controller: _betterPlayerController, key: _betterPlayerKey, ), ), ``` -------------------------------- ### Configure Player Controls with BetterPlayerControlsConfiguration Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/controlsconfiguration.md This snippet demonstrates how to initialize BetterPlayerConfiguration with custom control settings. It shows how to pass a BetterPlayerControlsConfiguration instance to set properties like text and icon colors. ```dart var betterPlayerConfiguration = BetterPlayerConfiguration( controlsConfiguration: BetterPlayerControlsConfiguration( textColor: Colors.black, iconsColor: Colors.black, ), ); ``` -------------------------------- ### Configure Fairplay DRM Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/drmconfiguration.md Sets up Fairplay DRM for network video sources, requiring certificate and license URLs. This is supported on iOS. ```dart BetterPlayerDataSource _fairplayDataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, Constants.fairplayHlsUrl, drmConfiguration: BetterPlayerDrmConfiguration( drmType: BetterPlayerDrmType.fairplay, certificateUrl: Constants.fairplayCertificateUrl, licenseUrl: Constants.fairplayLicenseUrl, ), ); ``` -------------------------------- ### Configure Token-Based DRM Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/drmconfiguration.md Sets up token-based DRM for network video sources. Requires a valid authorization token. This is supported on Android and iOS. ```dart BetterPlayerDataSource dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "url", videoFormat: BetterPlayerVideoFormat.hls, drmConfiguration: BetterPlayerDrmConfiguration( drmType: BetterPlayerDrmType.token, token: "Bearer=token", ), ); ``` -------------------------------- ### Configure Network Subtitles with BetterPlayerDataSource Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/subtitlesconfiguration.md Demonstrates how to set up network-based subtitles for a video using BetterPlayerDataSource. It specifies the video URL and the network URL for the subtitle file. ```dart var dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4", subtitles: BetterPlayerSubtitlesSource.single( type: BetterPlayerSubtitlesSourceType.network, url: "https://dl.dropboxusercontent.com/s/71nzjo2ux3evxqk/example_subtitles.srt" ), ); ``` -------------------------------- ### Configure File Subtitles with BetterPlayerDataSource Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/subtitlesconfiguration.md Illustrates how to configure subtitles loaded from local files using BetterPlayerDataSource. It requires the video file path and the subtitle file path. ```dart var dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.file, "${directory.path}/testvideo.mp4", subtitles: BetterPlayerSubtitlesSource.single( type: BetterPlayerSubtitlesSourceType.file, url: "${directory.path}/example_subtitles.srt", ), ); ``` -------------------------------- ### Configure Multiple Network Subtitles with BetterPlayerDataSource Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/subtitlesconfiguration.md Shows how to provide multiple subtitle tracks for a single video, sourced from the network. This allows users to select different languages or versions of subtitles. ```dart var dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8", liveStream: false, useAsmsSubtitles: true, hlsTrackNames: ["Low quality", "Not so low quality", "Medium quality"], subtitles: [ BetterPlayerSubtitlesSource( type: BetterPlayerSubtitlesSourceType.network, name: "EN", urls: [ "https://dl.dropboxusercontent.com/s/71nzjo2ux3evxqk/example_subtitles.srt" ], ), BetterPlayerSubtitlesSource( type: BetterPlayerSubtitlesSourceType.network, name: "DE", urls: [ "https://dl.dropboxusercontent.com/s/71nzjo2ux3evxqk/example_subtitles.srt" ], ), ], ); ``` -------------------------------- ### Configure BetterPlayerPlaylist with Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/playlistconfiguration.md Instantiate and configure BetterPlayerPlaylistConfiguration to control playlist behavior such as looping and next video delay. This configuration object is then passed to the BetterPlayerPlaylist widget. ```dart var betterPlayerPlaylistConfiguration = BetterPlayerPlaylistConfiguration( loopVideos: false, nextVideoDelay: Duration(milliseconds: 5000), ); ``` ```dart ///How long user should wait for next video final Duration nextVideoDelay; ///Should videos be looped final bool loopVideos; ///Index of video that will start on playlist start. Id must be less than ///elements in data source list. Default is 0. final int initialStartIndex; ``` -------------------------------- ### Check Data Source Load Status with Dart in Better Player Plus Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/sourceload.md This snippet demonstrates how to check if a data source has been loaded successfully using the `setupDataSource` method of `BetterPlayerController`. It utilizes `.then()` to handle successful loading and `.catchError()` to manage errors, such as invalid URLs. The `videoLoading` variable is updated based on the outcome. ```dart betterPlayerController!.setupDataSource(source) .then((response) { // Source loaded successfully videoLoading = false; }) .catchError((error) async { // Source did not load, url might be invalid inspect(error); }); ``` -------------------------------- ### Add Dependency to pubspec.yaml Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/README.md To use Better Player Plus, add the dependency to your project's pubspec.yaml file. This ensures the package is available for use in your Flutter application. ```yaml dependencies: better_player_plus: ^1.1.2 ``` -------------------------------- ### List of Better Player Plus Events Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/events.md This snippet lists all the available event types that the Better Player Plus controller can emit. These events cover various player states and actions, such as initialization, playback, seeking, fullscreen, volume changes, progress updates, and more. ```dart initialized, play, pause, seekTo, openFullscreen, hideFullscreen, setVolume, progress, finished, exception, controlsVisible, controlsHiddenStart, controlsHiddenEnd, setSpeed, changedSubtitles, changedTrack, changedPlayerVisibility, changedResolution, pipStart, pipStop, setupDataSource, bufferingStart, bufferingUpdate, bufferingEnd, changedPlaylistItem ``` -------------------------------- ### Configure Network Subtitles with Styling in Dart Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt Demonstrates how to configure network subtitles for a video player using Better Player Plus. It includes setting up subtitle sources from URLs and customizing their appearance like font size, color, and background. This requires the 'better_player_plus' and 'flutter/material' packages. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class SubtitlesPlayerPage extends StatefulWidget { @override _SubtitlesPlayerPageState createState() => _SubtitlesPlayerPageState(); } class _SubtitlesPlayerPageState extends State { late BetterPlayerController _controller; @override void initState() { super.initState(); BetterPlayerDataSource dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", subtitles: [ BetterPlayerSubtitlesSource( type: BetterPlayerSubtitlesSourceType.network, name: "English", urls: ["https://example.com/subtitles_en.srt"], selectedByDefault: true, ), BetterPlayerSubtitlesSource( type: BetterPlayerSubtitlesSourceType.network, name: "Spanish", urls: ["https://example.com/subtitles_es.srt"], ), ], ); _controller = BetterPlayerController( BetterPlayerConfiguration( aspectRatio: 16 / 9, subtitlesConfiguration: BetterPlayerSubtitlesConfiguration( fontSize: 18, fontColor: Colors.white, backgroundColor: Colors.black54, outlineEnabled: true, outlineColor: Colors.black, outlineSize: 2.0, alignment: Alignment.bottomCenter, bottomPadding: 20, ), ), betterPlayerDataSource: dataSource, ); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Subtitles Player")), body: AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer(controller: _controller), ), ); } } ``` -------------------------------- ### Configure ClearKey DRM Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/drmconfiguration.md Configures ClearKey DRM for local file sources, using a map of key IDs to keys. This is supported on Android and requires specific MP4 file preparation. ```dart var _clearKeyDataSourceFile = BetterPlayerDataSource( BetterPlayerDataSourceType.file, await Utils.getFileUrl(Constants.fileTestVideoEncryptUrl), drmConfiguration: BetterPlayerDrmConfiguration( drmType: BetterPlayerDrmType.clearKey, clearKey: BetterPlayerClearKeyUtils.generate({ "f3c5e0361e6654b28f8049c778b23946": "a4631a153a443df9eed0593043db7519", "abba271e8bcf552bbd2e86a434a9a5d9": "69eaa802a6763af979e8d1940fb88392" })), ); ``` -------------------------------- ### Configure PiP Menu Item (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/pictureinpictureconfiguration.md Configures the Picture in Picture (PiP) menu item within the player controls. The `enablePip` variable in `BetterPlayerControlsConfiguration` can be used to show or hide the PiP option, and `pipMenuIcon` allows customization of the menu icon. ```dart // To disable the PiP menu item: BetterPlayerControlsConfiguration(enablePip: false) // To change the PiP control menu icon: BetterPlayerControlsConfiguration(pipMenuIcon: Icons.abc) ``` -------------------------------- ### Configure Buffering with BetterPlayerBufferingConfiguration (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/bufferingconfiguration.md Set up custom buffering settings for Better Player Plus using the BetterPlayerBufferingConfiguration class within BetterPlayerDataSource. This allows for fine-tuning the buffering experience, such as minimum and maximum buffer durations, and buffer duration for playback and rebuffer events. Currently, this feature is only available on Android. ```dart BetterPlayerDataSource _betterPlayerDataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, Constants.elephantDreamVideoUrl, bufferingConfiguration: BetterPlayerBufferingConfiguration( minBufferMs: 50000, maxBufferMs: 13107200, bufferForPlaybackMs: 2500, bufferForPlaybackAfterRebufferMs: 5000, ), ); ``` -------------------------------- ### Configure Player Notifications in Dart Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/notificationconfiguration.md Sets up in-app media player notifications using the `BetterPlayerDataSource` and `BetterPlayerNotificationConfiguration` classes. This configuration allows displaying media titles, authors, and images in the notification, and specifies the activity to launch when the notification is clicked. The `showNotification` parameter controls whether the notification is displayed. ```dart BetterPlayerDataSource dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, Constants.elephantDreamVideoUrl, notificationConfiguration: BetterPlayerNotificationConfiguration( showNotification: true, title: "Elephant dream", author: "Some author", imageUrl: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/African_Bush_Elephant.jpg/1200px-African_Bush_Elephant.jpg", activityName: "MainActivity", ), ); ``` -------------------------------- ### Control Video Playback with BetterPlayerController in Dart Source: https://context7.com/sunnatilloshavkatov/better_player_plus/llms.txt This Dart code snippet demonstrates initializing and utilizing BetterPlayerController to manage video playback. It covers setting up the data source, configuring playback options like aspect ratio and autoplay, and implementing UI controls for play, pause, seek, and speed adjustments. The controller handles the lifecycle of the video player. ```dart import 'package:better_player_plus/better_player_plus.dart'; import 'package:flutter/material.dart'; class ControlledPlayerPage extends StatefulWidget { @override _ControlledPlayerPageState createState() => _ControlledPlayerPageState(); } class _ControlledPlayerPageState extends State { late BetterPlayerController _controller; @override void initState() { super.initState(); BetterPlayerDataSource dataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", ); _controller = BetterPlayerController( BetterPlayerConfiguration( aspectRatio: 16 / 9, autoPlay: true, looping: false, handleLifecycle: true, ), betterPlayerDataSource: dataSource, ); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("Controlled Player")), body: Column( children: [ AspectRatio( aspectRatio: 16 / 9, child: BetterPlayer(controller: _controller), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( icon: Icon(Icons.play_arrow), onPressed: () => _controller.play(), ), IconButton( icon: Icon(Icons.pause), onPressed: () => _controller.pause(), ), IconButton( icon: Icon(Icons.replay_10), onPressed: () async { final position = await _controller.videoPlayerController?.position; if (position != null) { _controller.seekTo(position - Duration(seconds: 10)); } }, ), IconButton( icon: Icon(Icons.forward_10), onPressed: () async { final position = await _controller.videoPlayerController?.position; if (position != null) { _controller.seekTo(position + Duration(seconds: 10)); } }, ), ], ), Slider( min: 0.5, max: 2.0, value: 1.0, onChanged: (value) => _controller.setSpeed(value), ), ], ), ); } } ``` -------------------------------- ### Check Picture in Picture Support (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/pictureinpictureconfiguration.md Checks if the current device supports Picture in Picture (PiP) mode. This method returns a boolean value indicating support. It is crucial to call this before attempting to enable PiP to avoid errors on unsupported devices. ```dart _betterPlayerController.isPictureInPictureSupported(); ``` -------------------------------- ### Override Aspect Ratio at Runtime with Better Player Plus Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/overriddenaspectratio.md Demonstrates how to override the `aspectRatio` parameter of `BetterPlayerConfiguration` at runtime. This is achieved by calling the `setOverriddenAspectRatio` method on the `betterPlayerController` instance. No specific dependencies are required beyond the Better Player Plus library itself. ```dart betterPlayerController.setOverriddenAspectRatio(1.0); ``` -------------------------------- ### BetterPlayerControlsConfiguration Properties Overview Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/controlsconfiguration.md This section lists and describes the various properties available within the BetterPlayerControlsConfiguration class. These properties allow for extensive customization of the player's UI, including colors, icons, and feature enablement. ```dart ///Color of the control bars final Color controlBarColor; ///Color of texts final Color textColor; ///Color of icons final Color iconsColor; ///Icon of play final IconData playIcon; ///Icon of pause final IconData pauseIcon; ///Icon of mute final IconData muteIcon; ///Icon of unmute final IconData unMuteIcon; ///Icon of fullscreen mode enable final IconData fullscreenEnableIcon; ///Icon of fullscreen mode disable final IconData fullscreenDisableIcon; ///Cupertino only icon, icon of skip final IconData skipBackIcon; ///Cupertino only icon, icon of forward final IconData skipForwardIcon; ///Flag used to enable/disable fullscreen final bool enableFullscreen; ///Flag used to enable/disable mute final bool enableMute; ///Flag used to enable/disable progress texts final bool enableProgressText; ///Flag used to enable/disable progress bar final bool enableProgressBar; ///Flag used to enable/disable progress bar drag final bool enableProgressBarDrag; ///Flag used to enable/disable play-pause final bool enablePlayPause; ///Flag used to enable skip forward and skip back final bool enableSkips; ///Progress bar played color final Color progressBarPlayedColor; ///Progress bar circle color final Color progressBarHandleColor; ///Progress bar buffered video color final Color progressBarBufferedColor; ///Progress bar background color final Color progressBarBackgroundColor; ///Time to hide controls final Duration controlsHideTime; ///Parameter used to build custom controls final Widget Function( BetterPlayerController controller, Function(bool visibility) onPlayerVisibilityChanged, BetterPlayerControlsConfiguration controlsConfiguration, ) customControlsBuilder; ///Parameter used to change theme of the player final BetterPlayerTheme playerTheme; ///Flag used to show/hide controls final bool showControls; ///Flag used to show controls on init final bool showControlsOnInitialize; ///Control bar height final double controlBarHeight; ///Live text color; final Color liveTextColor; ///Flag used to show/hide overflow menu which contains playback, subtitles, ///qualities options. final bool enableOverflowMenu; ///Flag used to show/hide playback speed final bool enablePlaybackSpeed; ///Flag used to show/hide subtitles final bool enableSubtitles; ///Flag used to show/hide qualities final bool enableQualities; ///Flag used to show/hide PiP mode final bool enablePip; ///Flag used to enable/disable retry feature final bool enableRetry; ///Flag used to show/hide audio tracks final bool enableAudioTracks; ///Custom items of overflow menu final List overflowMenuCustomItems; ///Icon of the overflow menu final IconData overflowMenuIcon; ///Icon of the playback speed menu item from overflow menu final IconData playbackSpeedIcon; ///Icon of the subtitles menu item from overflow menu final IconData subtitlesIcon; ///Icon of the qualities menu item from overflow menu final IconData qualitiesIcon; ///Icon of the audios menu item from overflow menu final IconData audioTracksIcon; ///Color of overflow menu icons final Color overflowMenuIconsColor; ///Time which will be used once user uses forward final int forwardSkipTimeInMilliseconds; ///Time which will be used once user uses backward final int backwardSkipTimeInMilliseconds; ///Color of default loading indicator final Color loadingColor; ///Widget which can be used instead of default progress final Widget loadingWidget; ///Color of the background, when no frame is displayed. final Color backgroundColor; ///Quality of Gaussian Blur for x (iOS only). final double sigmaX; ///Quality of Gaussian Blur for y (iOS only). final double sigmaY; ``` -------------------------------- ### Pre-cache Video Data with Better Player Plus Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/cacheconfiguration.md Initiates the pre-caching process for a given BetterPlayerDataSource before the video is played. This can improve playback performance by downloading content in advance. ```dart betterPlayerController.preCache(_betterPlayerDataSource); ``` -------------------------------- ### Configure Translations with BetterPlayerTranslations (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/translationsconfiguration.md Provides custom translations for video player UI elements using the BetterPlayerTranslations class. This involves creating instances of BetterPlayerTranslations for each desired language and passing them as a list to the BetterPlayerConfiguration. Each translation object requires a language code and translated strings for various player messages and controls. Ensure that app-level localizations are set up for this to function correctly. ```dart translations: [ BetterPlayerTranslations( languageCode: "language_code for example pl", generalDefaultError: "translated text", generalNone: "translated text", generalDefault: "translated text", playlistLoadingNextVideo: "translated text", controlsLive: "translated text", controlsNextVideoIn: "translated text", overflowMenuPlaybackSpeed: "translated text", overflowMenuSubtitles: "translated text", overflowMenuQuality: "translated text", ), BetterPlayerTranslations( languageCode: "other language for example cz", generalDefaultError: "translated text", generalNone: "translated text", generalDefault: "translated text", playlistLoadingNextVideo: "translated text", controlsLive: "translated text", controlsNextVideoIn: "translated text", overflowMenuPlaybackSpeed: "translated text", overflowMenuSubtitles: "translated text", overflowMenuQuality: "translated text", ), ], ``` -------------------------------- ### Enable Picture in Picture Mode (Dart) Source: https://github.com/sunnatilloshavkatov/better_player_plus/blob/master/doc/pictureinpictureconfiguration.md Enables Picture in Picture (PiP) mode for the Better Player. This function requires a GlobalKey associated with the BetterPlayer widget to correctly manage the PiP view. Ensure PiP is supported before calling this method. ```dart _betterPlayerController.enablePictureInPicture(_betterPlayerKey); ```