### Flutter Video Player Example Source: https://pub.dev/documentation/video_player/latest/index.html This example demonstrates how to initialize and play a video from a network URL using the VideoPlayerController. It includes basic playback controls and aspect ratio handling. Ensure the video URL is valid and accessible. ```dart import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; void main() => runApp(const VideoApp()); /// Stateful widget to fetch and then display video content. class VideoApp extends StatefulWidget { const VideoApp({super.key}); @override _VideoAppState createState() => _VideoAppState(); } class _VideoAppState extends State { late VideoPlayerController _controller; @override void initState() { super.initState(); _controller = VideoPlayerController.networkUrl( Uri.parse( 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4', ), ) ..initialize().then((_) { // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. setState(() {}); }); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Video Demo', home: Scaffold( body: Center( child: _controller.value.isInitialized ? AspectRatio( aspectRatio: _controller.value.aspectRatio, child: VideoPlayer(_controller), ) : Container(), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _controller.value.isPlaying ? _controller.pause() : _controller.play(); }); }, child: Icon( _controller.value.isPlaying ? Icons.pause : Icons.play_arrow, ), ), ), ); } @override void dispose() { _controller.dispose(); super.dispose(); } } ``` -------------------------------- ### play method Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/play.html Starts playing the video. If the video is at the end, this method starts playing from the beginning. This method returns a future that completes as soon as the "play" command has been sent to the platform, not when playback itself is totally finished. ```APIDOC ## play() ### Description Starts playing the video. If the video is at the end, this method starts playing from the beginning. This method returns a future that completes as soon as the "play" command has been sent to the platform, not when playback itself is totally finished. ### Method Future ### Parameters None ### Response Completes when the "play" command is sent to the platform. ``` -------------------------------- ### startFraction method Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange-class.html Calculates the fraction of the total video duration that the `start` property represents. Assumes the provided `duration` is the total length of the video. ```APIDOC ## startFraction(Duration duration) → double ### Description Assumes that `duration` is the total length of the video that this DurationRange is a segment from. It returns the percentage that start is through the entire video. ### Parameters * **duration** (Duration) - Required - The total duration of the video. ### Returns double - The fraction of the total video duration represented by the start time. ``` -------------------------------- ### Define Caption Start Time Source: https://pub.dev/documentation/video_player/latest/video_player/Caption/start.html Use the 'start' property to specify the exact time a caption should appear. This property is of type Duration. ```dart final Duration start; ``` -------------------------------- ### start property Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange-class.html The beginning of the segment described relative to the beginning of the entire video. This property is final and should be less than or equal to the `end` property. ```APIDOC ## start → Duration ### Description The beginning of the segment described relative to the beginning of the entire video. Should be shorter than or equal to end. ### Type Duration ``` -------------------------------- ### startFraction Method Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/startFraction.html Calculates the percentage of the total video duration that the start of this DurationRange represents. It assumes the provided duration is the total length of the video. ```APIDOC ## startFraction Method ### Description Assumes that `duration` is the total length of the video that this DurationRange is a segment from. It returns the percentage that start is through the entire video. ### Method Signature double startFraction(Duration duration) ### Parameters #### Path Parameters - **duration** (Duration) - The total length of the video. ### Returns - double - The fraction representing the start position of the DurationRange relative to the total video duration. ### Example For example, assume that the entire video is 4 minutes long. If start has a duration of one minute, this will return `0.25` since the DurationRange starts 25% of the way through the video's total length. ### Implementation ```dart double startFraction(Duration duration) { return start.inMilliseconds / duration.inMilliseconds; } ``` ``` -------------------------------- ### Get Available Audio Tracks Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/getAudioTracks.html Fetches a list of available audio tracks for the video. Returns an empty list if the video is not initialized. Throws an error if the controller is disposed. ```dart Future> getAudioTracks() async { if (_isDisposed) { throw StateError('VideoPlayerController is disposed'); } if (!value.isInitialized) { return []; } final List platformTracks = await _videoPlayerPlatform.getAudioTracks(_playerId); return platformTracks.map(_convertPlatformAudioTrack).toList(); } ``` -------------------------------- ### VideoPlayerController play() Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/play.html Starts playing the video. If the video is at the end, it seeks to the beginning before playing. This method returns a future that completes when the 'play' command is sent. ```dart Future play() async { if (value.position == value.duration) { await seekTo(Duration.zero); } value = value.copyWith(isPlaying: true); await _applyPlayPause(); } ``` -------------------------------- ### position property Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/position.html Gets the current playback position of the video. Returns null if the controller has been disposed. ```APIDOC ## position property ### Description Gets the current playback position of the video. This property returns a `Future` which resolves to the current playback time in seconds. If the controller has been disposed, it returns null. ### Method `get` ### Return Value - **Future**: A future that resolves to the current playback position as a `Duration` object, or null if the controller is disposed. ``` -------------------------------- ### Caption Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/Caption-class.html Creates a new Caption object with the specified number, start time, end time, and text. ```APIDOC ## Caption({required int number, required Duration start, required Duration end, required String text}) ### Description Creates a new Caption object. ### Parameters #### Path Parameters - **number** (int) - Required - The number that this caption was assigned. - **start** (Duration) - Required - When in the given video should this Caption begin displaying. - **end** (Duration) - Required - When in the given video should this Caption be dismissed. - **text** (String) - Required - The actual text that should appear on screen to be read between start and end. ``` -------------------------------- ### DurationRange Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange-class.html Initializes a new DurationRange object. It is assumed that the provided start and end Durations are valid and in the correct order (start <= end). ```APIDOC ## DurationRange(Duration start, Duration end) ### Description Trusts that the given `start` and `end` are actually in order. They should both be non-null. ### Parameters * **start** (Duration) - Required - The starting point of the time segment. * **end** (Duration) - Required - The ending point of the time segment. ``` -------------------------------- ### Calculate Start Fraction of Video Segment Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/startFraction.html Calculates the fraction of the total video duration that the start of this DurationRange represents. Assumes the provided duration is the total video length. ```dart double startFraction(Duration duration) { return start.inMilliseconds / duration.inMilliseconds; } ``` -------------------------------- ### Check Audio Track Support and Get Tracks Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/isAudioTrackSupportAvailable.html Demonstrates how to check if audio track selection is supported and retrieve available tracks if it is. Use this to conditionally show UI for audio track selection. ```dart if (controller.isAudioTrackSupportAvailable()) { final tracks = await controller.getAudioTracks(); // Show audio track selection UI } else { // Hide audio track selection UI or show unsupported message } ``` -------------------------------- ### getAudioTracks Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/getAudioTracks.html Gets the available audio tracks for the video. Returns a list of VideoAudioTrack objects containing metadata about each available audio track. The list may be empty if no audio tracks are available or if the video is not initialized. Throws an error if the video player is disposed. ```APIDOC ## getAudioTracks ### Description Gets the available audio tracks for the video. ### Method Future> ### Returns A list of `VideoAudioTrack` objects containing metadata about each available audio track. The list may be empty if no audio tracks are available or if the video is not initialized. ### Throws - `StateError`: If the video player controller is disposed. ``` -------------------------------- ### Get Captions List Source: https://pub.dev/documentation/video_player/latest/video_player/ClosedCaptionFile/captions.html Retrieves the full list of captions from a given file. Captions are ordered as they appear in the file. ```dart List get captions; ``` -------------------------------- ### DurationRange Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/DurationRange.html Constructs a DurationRange object. It requires a start and an end duration, and trusts that they are provided in the correct order and are non-null. ```APIDOC ## DurationRange Constructor ### Description Constructs a DurationRange object. It requires a start and an end duration, and trusts that they are provided in the correct order and are non-null. ### Parameters #### Path Parameters - **start** (Duration) - Required - The starting duration of the range. - **end** (Duration) - Required - The ending duration of the range. ### Implementation ```dart // TODO(stuartmorgan): Temporarily suppress warnings about not using const // in all of the other video player packages, fix this, and then update // the other packages to use const. // ignore: prefer_const_constructors_in_immutables DurationRange(this.start, this.end); ``` ``` -------------------------------- ### Get controlsList String Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerWebOptionsControls/controlsList.html This implementation generates a space-separated string of disallowed controls based on the allowDownload, allowFullscreen, and allowPlaybackRate flags. Use this to customize which controls are hidden from the user. ```dart String get controlsList { final controlsList = []; if (!allowDownload) { controlsList.add('nodownload'); } if (!allowFullscreen) { controlsList.add('nofullscreen'); } if (!allowPlaybackRate) { controlsList.add('noplaybackrate'); } return controlsList.join(' '); } ``` -------------------------------- ### initialize Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/initialize.html Attempts to open the given dataSource and load metadata about the video. ```APIDOC ## initialize() ### Description Attempts to open the given dataSource and load metadata about the video. ### Method Future initialize() ### Parameters None ### Response None ### Example ```dart await videoPlayerController.initialize(); ``` ``` -------------------------------- ### DurationRange Constructor Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/DurationRange.html The constructor for DurationRange initializes the start and end properties. It assumes the provided start and end durations are non-null and in the correct order. ```dart // TODO(stuartmorgan): Temporarily suppress warnings about not using const // in all of the other video player packages, fix this, and then update // the other packages to use const. // ignore: prefer_const_constructors_in_immutables DurationRange(this.start, this.end); ``` -------------------------------- ### VideoPlayerController.file Constructor Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.file.html Shows the implementation of the VideoPlayerController.file constructor, initializing the data source from a file path and setting the data source type to file. ```dart VideoPlayerController.file( File file, { Future? closedCaptionFile, this.videoPlayerOptions, this.httpHeaders = const {}, this.viewType = platform_interface.VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSource = Uri.file(file.absolute.path).toString(), dataSourceType = platform_interface.DataSourceType.file, package = null, formatHint = null, super(const VideoPlayerValue(duration: Duration.zero)); ``` -------------------------------- ### VideoAudioTrack Constructor Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoAudioTrack/VideoAudioTrack.html The actual implementation of the VideoAudioTrack constructor, assigning the provided arguments to the instance properties. ```dart const VideoAudioTrack({ required this.id, required this.isSelected, this.label, this.language, this.bitrate, this.sampleRate, this.channelCount, this.codec, }); ``` -------------------------------- ### isInitialized Property Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerValue/isInitialized.html Indicates whether or not the video has been loaded and is ready to play. ```APIDOC ## isInitialized Property ### Description Indicates whether or not the video has been loaded and is ready to play. ### Type bool ### Value `true` if the video is loaded and ready to play, `false` otherwise. ### Example ```dart if (videoPlayerValue.isInitialized) { // Video is ready to play } ``` ``` -------------------------------- ### VideoAudioTrack Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoAudioTrack/VideoAudioTrack.html Constructs an instance of VideoAudioTrack with the specified properties. ```APIDOC ## VideoAudioTrack Constructor ### Description Constructs an instance of VideoAudioTrack. ### Parameters #### Path Parameters - **id** (String) - Required - Unique identifier for the audio track. - **isSelected** (bool) - Required - Indicates if this track is currently selected. - **label** (String?) - Optional - A human-readable label for the audio track. - **language** (String?) - Optional - The language code for the audio track (e.g., 'en', 'es'). - **bitrate** (int?) - Optional - The bitrate of the audio track in bits per second. - **sampleRate** (int?) - Optional - The sample rate of the audio track in Hz. - **channelCount** (int?) - Optional - The number of audio channels. - **codec** (String?) - Optional - The audio codec used (e.g., 'aac', 'mp3'). ``` -------------------------------- ### closedCaptionFile Property Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/closedCaptionFile.html Gets the file containing closed captions for the video, if any. ```APIDOC ## closedCaptionFile Property ### Description Returns the file containing closed captions for the video, if any. ### Getter `Future? closedCaptionFile` ### Returns - `Future?`: A future that resolves to the `ClosedCaptionFile` object if captions are available, otherwise null. ### Implementation ```dart Future? get closedCaptionFile { return _closedCaptionFileFuture; } ``` ``` -------------------------------- ### VideoPlayerController.initialize Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/initialize.html This snippet shows the core logic for initializing a VideoPlayerController. It handles different data source types (asset, network, file, contentUri), configures playback options, sets up event listeners for player events (initialized, completed, buffering, etc.), and error handling. ```dart Future initialize() async { final bool allowBackgroundPlayback = videoPlayerOptions?.allowBackgroundPlayback ?? false; if (!allowBackgroundPlayback) { _lifeCycleObserver = _VideoAppLifeCycleObserver(this); } _lifeCycleObserver?.initialize(); _creatingCompleter = Completer(); final platform_interface.DataSource dataSourceDescription; switch (dataSourceType) { case platform_interface.DataSourceType.asset: dataSourceDescription = platform_interface.DataSource( sourceType: platform_interface.DataSourceType.asset, asset: dataSource, package: package, ); case platform_interface.DataSourceType.network: dataSourceDescription = platform_interface.DataSource( sourceType: platform_interface.DataSourceType.network, uri: dataSource, formatHint: formatHint, httpHeaders: httpHeaders, ); case platform_interface.DataSourceType.file: dataSourceDescription = platform_interface.DataSource( sourceType: platform_interface.DataSourceType.file, uri: dataSource, httpHeaders: httpHeaders, ); case platform_interface.DataSourceType.contentUri: dataSourceDescription = platform_interface.DataSource( sourceType: platform_interface.DataSourceType.contentUri, uri: dataSource, ); } final creationOptions = platform_interface.VideoCreationOptions( dataSource: dataSourceDescription, viewType: viewType, ); if (videoPlayerOptions?.mixWithOthers != null) { await _videoPlayerPlatform.setMixWithOthers( videoPlayerOptions!.mixWithOthers, ); } _playerId = (await _videoPlayerPlatform.createWithOptions(creationOptions)) ?? kUninitializedPlayerId; _creatingCompleter!.complete(null); final initializingCompleter = Completer(); // Apply the web-specific options if (kIsWeb && videoPlayerOptions?.webOptions != null) { await _videoPlayerPlatform.setWebOptions( _playerId, videoPlayerOptions!.webOptions!, ); } void eventListener(platform_interface.VideoEvent event) { if (_isDisposed) { return; } switch (event.eventType) { case platform_interface.VideoEventType.initialized: value = value.copyWith( duration: event.duration, size: event.size, rotationCorrection: event.rotationCorrection, isInitialized: event.duration != null, errorDescription: null, isCompleted: false, ); assert( !initializingCompleter.isCompleted, 'VideoPlayerController already initialized. This is typically a ' 'sign that an implementation of the VideoPlayerPlatform ' '(${_videoPlayerPlatform.runtimeType}) has a bug and is sending ' 'more than one initialized event per instance.', ); if (initializingCompleter.isCompleted) { throw StateError('VideoPlayerController already initialized'); } initializingCompleter.complete(null); _applyLooping(); _applyVolume(); _applyPlayPause(); case platform_interface.VideoEventType.completed: // In this case we need to stop _timer, set isPlaying=false, and // position=value.duration. Instead of setting the values directly, // we use pause() and seekTo() to ensure the platform stops playing // and seeks to the last frame of the video. pause().then((void pauseResult) => seekTo(value.duration)); value = value.copyWith(isCompleted: true); case platform_interface.VideoEventType.bufferingUpdate: value = value.copyWith(buffered: event.buffered); case platform_interface.VideoEventType.bufferingStart: value = value.copyWith(isBuffering: true); case platform_interface.VideoEventType.bufferingEnd: value = value.copyWith(isBuffering: false); case platform_interface.VideoEventType.isPlayingStateUpdate: if (event.isPlaying ?? false) { value = value.copyWith( isPlaying: event.isPlaying, isCompleted: false, ); } else { value = value.copyWith(isPlaying: event.isPlaying); } case platform_interface.VideoEventType.unknown: break; } } if (_closedCaptionFileFuture != null) { await _updateClosedCaptionWithFuture(_closedCaptionFileFuture); } void errorListener(Object obj) { final e = obj as PlatformException; value = VideoPlayerValue.erroneous(e.message!) _timer?.cancel(); if (!initializingCompleter.isCompleted) { initializingCompleter.completeError(obj); } } _eventSubscription = _videoPlayerPlatform .videoEventsFor(_playerId) .listen(eventListener, onError: errorListener); return initializingCompleter.future; } ``` -------------------------------- ### VideoPlayerController.networkUrl Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.networkUrl.html Shows the implementation details of the VideoPlayerController.networkUrl constructor. This includes setting up internal variables and initializing the base class with network data source information. ```dart VideoPlayerController.networkUrl( Uri url, { this.formatHint, Future? closedCaptionFile, this.videoPlayerOptions, this.httpHeaders = const {}, this.viewType = platform_interface.VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSource = url.toString(), dataSourceType = platform_interface.DataSourceType.network, package = null, super(const VideoPlayerValue(duration: Duration.zero)); ``` -------------------------------- ### Get channelCount Source: https://pub.dev/documentation/video_player/latest/video_player/VideoAudioTrack/channelCount.html Access the channelCount property to retrieve the number of audio channels. This value can be null. ```dart final int? channelCount; ``` -------------------------------- ### VideoPlayerController.network Constructor Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.network.html Provides the implementation details for the VideoPlayerController.network constructor. This includes setting the data source, type, and initializing the video player value. ```dart @Deprecated('Use VideoPlayerController.networkUrl instead') VideoPlayerController.network( this.dataSource, { this.formatHint, Future? closedCaptionFile, this.videoPlayerOptions, this.httpHeaders = const {}, this.viewType = platform_interface.VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSourceType = platform_interface.DataSourceType.network, package = null, super(const VideoPlayerValue(duration: Duration.zero)); ``` -------------------------------- ### Get Video Position Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/position.html Retrieves the current playback position of the video. Returns null if the controller has been disposed. ```dart Future get position async { if (_isDisposed) { return null; } return _videoPlayerPlatform.getPosition(_playerId); } ``` -------------------------------- ### VideoAudioTrack Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoAudioTrack-class.html Constructs an instance of VideoAudioTrack with specified audio track properties. ```APIDOC ## VideoAudioTrack Constructor ### Description Constructs an instance of VideoAudioTrack. ### Parameters - **id** (String) - Required - Unique identifier for the audio track. - **isSelected** (bool) - Required - Whether this track is currently selected. - **label** (String?) - Optional - Human-readable label for the track. - **language** (String?) - Optional - Language code of the audio track (e.g., 'en', 'es', 'und'). - **bitrate** (int?) - Optional - Bitrate of the audio track in bits per second. - **sampleRate** (int?) - Optional - Sample rate of the audio track in Hz. - **channelCount** (int?) - Optional - Number of audio channels. - **codec** (String?) - Optional - Audio codec used (e.g., 'aac', 'mp3', 'ac3'). ``` -------------------------------- ### VideoPlayer Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayer/VideoPlayer.html Initializes a new VideoPlayer widget with a required controller and an optional key. ```APIDOC ## VideoPlayer.new ### Description Initializes a new VideoPlayer widget. It requires a `VideoPlayerController` to manage video playback and accepts an optional `Key` for widget identification. ### Constructor Signature ```dart const VideoPlayer(this.controller, {Key? key}); ``` ### Parameters #### Positional Parameters - **controller** (VideoPlayerController) - Required - The controller to use for all video rendered in this widget. #### Named Parameters - **key** (Key?) - Optional - An optional key for widget identification. ``` -------------------------------- ### SubRipCaptionFile Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/SubRipCaptionFile/SubRipCaptionFile.html Initializes a SubRipCaptionFile by parsing the provided file contents. Assumes the input string is in the SubRip format. ```dart SubRipCaptionFile(this.fileContents) : _captions = _parseCaptionsFromSubRipString(fileContents); ``` -------------------------------- ### Get Captions List Source: https://pub.dev/documentation/video_player/latest/video_player/SubRipCaptionFile/captions.html This getter returns the list of captions stored in the SubRipCaptionFile. The captions are ordered as they appear in the source file. ```dart @override List get captions => _captions; ``` -------------------------------- ### Implementation of isAudioTrackSupportAvailable Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/isAudioTrackSupportAvailable.html This is the internal implementation of the `isAudioTrackSupportAvailable` method, which delegates the check to the platform's video player implementation. ```dart bool isAudioTrackSupportAvailable() { return _videoPlayerPlatform.isAudioTrackSupportAvailable(); } ``` -------------------------------- ### VideoPlayerController.contentUri Constructor Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.contentUri.html This is the implementation of the VideoPlayerController.contentUri constructor. It asserts that the platform is Android and initializes the controller with the provided content URI. ```dart VideoPlayerController.contentUri( Uri contentUri, { Future? closedCaptionFile, this.videoPlayerOptions, this.viewType = platform_interface.VideoViewType.textureView, }) : assert( defaultTargetPlatform == TargetPlatform.android, 'VideoPlayerController.contentUri is only supported on Android.', ), _closedCaptionFileFuture = closedCaptionFile, dataSource = contentUri.toString(), dataSourceType = platform_interface.DataSourceType.contentUri, package = null, formatHint = null, httpHeaders = const {}, super(const VideoPlayerValue(duration: Duration.zero)); ``` -------------------------------- ### Get Captions Source: https://pub.dev/documentation/video_player/latest/video_player/ClosedCaptionFile/captions.html Retrieves the full list of captions from a given closed caption file. The captions are returned in the order they appear in the file. ```APIDOC ## get captions ### Description Returns the full list of captions from a given file, ordered as they appear in the file. ### Method Getter ### Return Type List ``` -------------------------------- ### VideoPlayerWebOptions Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerWebOptions-class.html Constructs a VideoPlayerWebOptions object to configure web player settings. Allows customization of controls, remote playback, and poster image. ```APIDOC ## Constructors ### VideoPlayerWebOptions ```dart VideoPlayerWebOptions({VideoPlayerWebOptionsControls controls = const VideoPlayerWebOptionsControls.disabled(), bool allowContextMenu = true, bool allowRemotePlayback = true, Uri? poster}) ``` **Description**: VideoPlayerWebOptions can be optionally used to set additional web settings. **Parameters**: * **controls** (VideoPlayerWebOptionsControls) - Optional - Additional settings for how control options are displayed. Defaults to `const VideoPlayerWebOptionsControls.disabled()`. * **allowContextMenu** (bool) - Optional - Whether context menu (right click) is allowed. Defaults to `true`. * **allowRemotePlayback** (bool) - Optional - Whether remote playback is allowed. Defaults to `true`. * **poster** (Uri?) - Optional - The URL of the poster image to be displayed before the video starts. ``` -------------------------------- ### VideoAudioTrack Constructor Signature Source: https://pub.dev/documentation/video_player/latest/video_player/VideoAudioTrack/VideoAudioTrack.html Defines the parameters for creating a VideoAudioTrack instance. All parameters are optional except for 'id' and 'isSelected'. ```dart const VideoAudioTrack({ 1. required String id, 2. required bool isSelected, 3. String? label, 4. String? language, 5. int? bitrate, 6. int? sampleRate, 7. int? channelCount, 8. String? codec, }) ``` -------------------------------- ### Get Closed Caption File Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/closedCaptionFile.html Retrieves the future containing the closed caption file for the video. This property returns null if no captions are available. ```dart Future? get closedCaptionFile { return _closedCaptionFileFuture; } ``` -------------------------------- ### VideoPlayerController.asset Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.asset.html Constructs a VideoPlayerController playing a video from an asset. The name of the asset is given by the `dataSource` argument and must not be null. The `package` argument must be non-null when the asset comes from a package and null otherwise. The `viewType` option allows the caller to request a specific display mode for the video. Platforms that do not support the request view type will ignore this parameter. ```APIDOC ## VideoPlayerController.asset ### Description Constructs a VideoPlayerController playing a video from an asset. ### Parameters #### Path Parameters * **dataSource** (String) - Required - The name of the asset. * **package** (String?) - Optional - The package name if the asset comes from a package. * **closedCaptionFile** (Future?) - Optional - A future that resolves to the closed caption file. * **videoPlayerOptions** (VideoPlayerOptions?) - Optional - Options for the video player. * **viewType** (VideoViewType) - Optional - The desired view type for the video player. Defaults to `platform_interface.VideoViewType.textureView`. ``` -------------------------------- ### DurationRange toString Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/toString.html Overrides the default toString method to provide a custom string representation including the start and end values of the duration range. ```dart @override String toString() => '${objectRuntimeType(this, 'DurationRange')}(start: $start, end: $end)'; ``` -------------------------------- ### end property Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange-class.html The end of the segment described as a duration relative to the beginning of the entire video. This property is final, non-null, and expected to be greater than or equal to the `start` property. ```APIDOC ## end → Duration ### Description The end of the segment described as a duration relative to the beginning of the entire video. This is expected to be non-null and longer than or equal to start. ### Type Duration ``` -------------------------------- ### VideoPlayerController.asset Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.asset.html Shows the internal implementation of the VideoPlayerController.asset constructor. It initializes various properties including the data source type, headers, and the initial video player value. ```dart VideoPlayerController.asset( this.dataSource, { this.package, Future? closedCaptionFile, this.videoPlayerOptions, this.viewType = platform_interface.VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSourceType = platform_interface.DataSourceType.asset, formatHint = null, httpHeaders = const {}, super(const VideoPlayerValue(duration: Duration.zero)); ``` -------------------------------- ### VideoProgressColors Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoProgressColors-class.html Initializes VideoProgressColors with customizable colors for video progress indication. Any color property can be set to a desired value, with predefined defaults. ```APIDOC ## VideoProgressColors ### Description Used to configure the VideoProgressIndicator widget's colors for how it describes the video's status. The widget uses default colors that are customizable through this class. ### Constructors `VideoProgressColors({Color playedColor = const Color.fromRGBO(255, 0, 0, 0.7), Color bufferedColor = const Color.fromRGBO(50, 50, 200, 0.2), Color backgroundColor = const Color.fromRGBO(200, 200, 200, 0.5)})` Any property can be set to any color. They each have defaults. ### Properties - `playedColor` (Color) - Optional - Defaults to red at 70% opacity. This fills up a portion of VideoProgressIndicator to represent how much of the video has played so far. - `bufferedColor` (Color) - Optional - Defaults to blue at 20% opacity. This fills up a portion of VideoProgressIndicator to represent how much of the video has buffered so far. - `backgroundColor` (Color) - Optional - Defaults to gray at 50% opacity. This is the background color behind both playedColor and bufferedColor to denote the total size of the video compared to either of those values. ``` -------------------------------- ### VideoPlayerController.network Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.network.html Constructs a VideoPlayerController playing a network video. The URI for the video is given by the `dataSource` argument. This constructor is deprecated and `VideoPlayerController.networkUrl` should be used instead. ```APIDOC ## VideoPlayerController.network(String dataSource, {VideoFormat? formatHint, Future? closedCaptionFile, VideoPlayerOptions? videoPlayerOptions, Map httpHeaders = const {}, VideoViewType viewType = platform_interface.VideoViewType.textureView}) ### Description Constructs a VideoPlayerController playing a network video. The URI for the video is given by the `dataSource` argument. **Android only**: The `formatHint` option allows the caller to override the video format detection code. The `viewType` option allows the caller to request a specific display mode for the video. Platforms that do not support the requested view type will ignore this parameter. `httpHeaders` option allows to specify HTTP headers for the request to the `dataSource`. ### Parameters #### Path Parameters * **dataSource** (String) - Required - The URI for the video. * **formatHint** (VideoFormat?) - Optional - Allows the caller to override the video format detection code (Android only). * **closedCaptionFile** (Future?) - Optional - A future that resolves to the closed caption file. * **videoPlayerOptions** (VideoPlayerOptions?) - Optional - Options for the video player. * **httpHeaders** (Map) - Optional - HTTP headers for the request to the dataSource. Defaults to an empty map. * **viewType** (VideoViewType) - Optional - The display mode for the video. Defaults to `platform_interface.VideoViewType.textureView`. ### Deprecated This constructor is deprecated. Use `VideoPlayerController.networkUrl` instead. ``` -------------------------------- ### DurationRange operator == implementation Source: https://pub.dev/documentation/video_player/latest/video_player/DurationRange/operator_equals.html This snippet shows the implementation of the equality operator for the DurationRange class. It checks for object identity, type compatibility, and equality of the start and end properties. ```dart @override bool operator ==(Object other) => identical(this, other) || other is DurationRange && runtimeType == other.runtimeType && start == other.start && end == other.end; ``` -------------------------------- ### Caption None Constant Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/Caption/none-constant.html This constant defines a caption object with zero start and end durations, and an empty text string. It's used to represent the absence of a caption. ```dart static const Caption none = Caption( number: 0, start: Duration.zero, end: Duration.zero, text: '', ); ``` -------------------------------- ### Instantiate WebVTTCaptionFile with WebVTT String Source: https://pub.dev/documentation/video_player/latest/video_player/WebVTTCaptionFile/WebVTTCaptionFile.html Use this constructor to parse a string containing WebVTT formatted captions. Ensure the input string adheres to the WebVTT specification. ```dart WebVTTCaptionFile(String fileContents) : _captions = _parseCaptionsFromWebVTTString(fileContents); ``` -------------------------------- ### Caption toString Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/Caption/toString.html Overrides the default toString method to provide a detailed string representation of the Caption object, including its number, start time, end time, and text. Useful for debugging. ```dart @override String toString() { return '${objectRuntimeType(this, 'Caption')}(' 'number: $number, 'start: $start, 'end: $end, 'text: $text)'; } ``` -------------------------------- ### VideoPlayerWebOptions Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerWebOptions/VideoPlayerWebOptions.html Defines the default values for web options, including controls, context menu, remote playback, and poster image. ```dart const VideoPlayerWebOptions({ this.controls = const VideoPlayerWebOptionsControls.disabled(), this.allowContextMenu = true, this.allowRemotePlayback = true, this.poster, }); ``` -------------------------------- ### VideoPlayerController Constructors Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController-class.html Constructs a VideoPlayerController for different data sources. ```APIDOC ## VideoPlayerController.asset Constructs a VideoPlayerController playing a video from an asset. ### Parameters - **dataSource** (String) - The asset path to the video file. - **package** (String?) - The package that the asset was loaded from. - **closedCaptionFile** (Future?) - An optional file containing closed captions. - **videoPlayerOptions** (VideoPlayerOptions?) - Optional additional configuration options. - **viewType** (VideoViewType) - The requested display mode for the video. Defaults to platform_interface.VideoViewType.textureView. ## VideoPlayerController.contentUri Constructs a VideoPlayerController playing a video from a contentUri. ### Parameters - **contentUri** (Uri) - The content URI to the video. - **closedCaptionFile** (Future?) - An optional file containing closed captions. - **videoPlayerOptions** (VideoPlayerOptions?) - Optional additional configuration options. - **viewType** (VideoViewType) - The requested display mode for the video. Defaults to platform_interface.VideoViewType.textureView. ## VideoPlayerController.file Constructs a VideoPlayerController playing a video from a file. ### Parameters - **file** (File) - The file to play. - **closedCaptionFile** (Future?) - An optional file containing closed captions. - **videoPlayerOptions** (VideoPlayerOptions?) - Optional additional configuration options. - **httpHeaders** (Map) - HTTP headers to use for the request. Defaults to an empty map. - **viewType** (VideoViewType) - The requested display mode for the video. Defaults to platform_interface.VideoViewType.textureView. ## VideoPlayerController.network Constructs a VideoPlayerController playing a network video. ### Parameters - **dataSource** (String) - The URI to the network video. - **formatHint** (VideoFormat?) - Android only. Overrides the platform's generic file format detection. - **closedCaptionFile** (Future?) - An optional file containing closed captions. - **videoPlayerOptions** (VideoPlayerOptions?) - Optional additional configuration options. - **httpHeaders** (Map) - HTTP headers to use for the request. Defaults to an empty map. - **viewType** (VideoViewType) - The requested display mode for the video. Defaults to platform_interface.VideoViewType.textureView. ## VideoPlayerController.networkUrl Constructs a VideoPlayerController playing a network video. ### Parameters - **url** (Uri) - The URI to the network video. - **formatHint** (VideoFormat?) - Android only. Overrides the platform's generic file format detection. - **closedCaptionFile** (Future?) - An optional file containing closed captions. - **videoPlayerOptions** (VideoPlayerOptions?) - Optional additional configuration options. - **httpHeaders** (Map) - HTTP headers to use for the request. Defaults to an empty map. - **viewType** (VideoViewType) - The requested display mode for the video. Defaults to platform_interface.VideoViewType.textureView. ``` -------------------------------- ### Override Equality Operator (==) in Dart Source: https://pub.dev/documentation/video_player/latest/video_player/Caption/operator_equals.html This snippet shows how to override the equality operator for a class. It checks for identity, type, and then compares specific properties (number, start, end, text) for equality. Ensure hashCode is also overridden for consistency. ```dart @override bool operator ==(Object other) => identical(this, other) || other is Caption && runtimeType == other.runtimeType && number == other.number && start == other.start && end == other.end && text == other.text; ``` -------------------------------- ### hashCode Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/Caption/hashCode.html This snippet shows the implementation of the hashCode getter, which uses Object.hash to generate a hash code based on the object's state (number, start, end, text). This is essential for using objects in hash-based collections like Sets and Maps. ```dart @override int get hashCode => Object.hash(number, start, end, text); ``` -------------------------------- ### VideoPlayerWebOptions Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerWebOptions/VideoPlayerWebOptions.html The VideoPlayerWebOptions constructor allows for the configuration of various web-related settings for the video player. ```APIDOC ## VideoPlayerWebOptions Constructor ### Description Allows for the configuration of web-specific options for the video player, such as playback controls, context menu behavior, remote playback, and a poster image. ### Method `const VideoPlayerWebOptions()` ### Parameters #### Named Parameters - **controls** (`VideoPlayerWebOptionsControls`) - Optional - The playback controls configuration. Defaults to `VideoPlayerWebOptionsControls.disabled()`. - **allowContextMenu** (`bool`) - Optional - Whether to allow the context menu. Defaults to `true`. - **allowRemotePlayback** (`bool`) - Optional - Whether to allow remote playback. Defaults to `true`. - **poster** (`Uri?`) - Optional - The URI for the poster image to display before playback starts. ``` -------------------------------- ### VideoPlayerController.contentUri Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.contentUri.html Constructs a VideoPlayerController playing a video from a contentUri. This will load the video from the input content-URI. This is supported on Android only. ```APIDOC ## VideoPlayerController.contentUri Constructor ### Description Constructs a VideoPlayerController playing a video from a contentUri. This will load the video from the input content-URI. This is supported on Android only. ### Parameters #### Path Parameters - **contentUri** (Uri) - Required - The URI of the video content to play. - **closedCaptionFile** (Future? ) - Optional - A future that resolves to a closed caption file. - **videoPlayerOptions** (VideoPlayerOptions? ) - Optional - Options for the video player. - **viewType** (VideoViewType) - Optional - The type of video view to use. Defaults to `platform_interface.VideoViewType.textureView`. ``` -------------------------------- ### WebVTTCaptionFile Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/WebVTTCaptionFile/WebVTTCaptionFile.html Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the WebVTT file format. ```APIDOC ## WebVTTCaptionFile(fileContents) ### Description Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the WebVTT file format. See: https://en.wikipedia.org/wiki/WebVTT ### Parameters #### Path Parameters - **fileContents** (String) - Required - The string content of the WebVTT file. ``` -------------------------------- ### WebVTTCaptionFile Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/WebVTTCaptionFile-class.html Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the WebVTT file format. ```APIDOC ## WebVTTCaptionFile(String fileContents) ### Description Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the WebVTT file format. ### Parameters #### Path Parameters - **fileContents** (String) - Required - The content of the WebVTT file. ``` -------------------------------- ### VideoPlayerWebOptionsControls.enabled() Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerWebOptionsControls-class.html Enables controls and sets how the options are displayed. Allows configuration of individual control features. ```APIDOC ## VideoPlayerWebOptionsControls.enabled() ### Description Enables controls and sets how the options are displayed. Allows configuration of individual control features. ### Method Constructor ### Endpoint N/A ### Parameters #### Query Parameters - **allowDownload** (bool) - Optional - Whether downloaded control is displayed. Defaults to true. - **allowFullscreen** (bool) - Optional - Whether fullscreen control is enabled. Defaults to true. - **allowPlaybackRate** (bool) - Optional - Whether playback rate control is displayed. Defaults to true. - **allowPictureInPicture** (bool) - Optional - Whether picture in picture control is displayed. Defaults to true. ### Request Example N/A ### Response N/A ``` -------------------------------- ### VideoPlayerController.file Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/VideoPlayerController.file.html Constructs a VideoPlayerController to play a video from a local file. It supports specifying closed caption files, video player options, and custom HTTP headers, which are particularly useful for HLS files (m3u8). ```APIDOC ## VideoPlayerController.file Constructor ### Description Constructs a VideoPlayerController playing a video from a file. This will load the file from a file:// URI constructed from `file`'s path. `httpHeaders` option allows to specify HTTP headers, mainly used for hls files like (m3u8). ### Parameters #### Path Parameters - **file** (File) - Required - The file to play. #### Named Parameters - **closedCaptionFile** (Future? ) - Optional - A future that resolves to the closed caption file. - **videoPlayerOptions** (VideoPlayerOptions? ) - Optional - Options for the video player. - **httpHeaders** (Map) - Optional - A map of HTTP headers to send with the request, defaults to an empty map. Primarily used for HLS files. - **viewType** (VideoViewType) - Optional - The type of video view to use, defaults to `platform_interface.VideoViewType.textureView`. ``` -------------------------------- ### Basic createState Implementation Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayer/createState.html This snippet shows the standard implementation of the createState method for a StatefulWidget, returning a new instance of its associated State subclass. ```dart @override State createState() => _SomeWidgetState(); ``` -------------------------------- ### isAudioTrackSupportAvailable Source: https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/isAudioTrackSupportAvailable.html Returns whether audio track selection is supported on this platform. This is useful for platforms like web where audio track selection may not be available. ```APIDOC ## isAudioTrackSupportAvailable() ### Description Returns whether audio track selection is supported on this platform. This method allows developers to query at runtime whether the current platform supports audio track selection functionality. This is useful for platforms like web where audio track selection may not be available. ### Returns - `bool`: `true` if `getAudioTracks` and `selectAudioTrack` are supported, `false` otherwise. ### Example Usage ```dart if (controller.isAudioTrackSupportAvailable()) { final tracks = await controller.getAudioTracks(); // Show audio track selection UI } else { // Hide audio track selection UI or show unsupported message } ``` ``` -------------------------------- ### SubRipCaptionFile Constructor Source: https://pub.dev/documentation/video_player/latest/video_player/SubRipCaptionFile/SubRipCaptionFile.html Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the SubRip file format. ```APIDOC ## SubRipCaptionFile Constructor ### Description Parses a string into a ClosedCaptionFile, assuming `fileContents` is in the SubRip file format. ### Parameters #### Path Parameters - **fileContents** (String) - Required - The string content of the SubRip caption file. ### See Also - https://en.wikipedia.org/wiki/SubRip ```