### Install Application Executable Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Installs the main application executable to the runtime destination. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Installs the main Flutter library file to the library directory. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configure Installation for Windows Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Sets up installation paths and options for Windows, ensuring support files are placed next to the executable for in-place running. ```cmake set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Installs any bundled plugin libraries to the library directory if they exist. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Configures the installation prefix to create a relocatable bundle in the build directory and sets up directories for data and libraries within the bundle. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Flutter Assets Directory Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Removes any existing assets and then copies the entire assets directory to the installation destination. This ensures assets are up-to-date. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Installs the Flutter assets directory to the application bundle. This ensures that assets are available at runtime. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Create YoutubePlayerController with Convenience Constructor Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Use the convenience constructor for a single video to simplify initialization. This is a shortcut for common single-video setups. ```dart final _controller = YoutubePlayerController.fromVideoId( videoId: '', autoPlay: false, params: const YoutubePlayerParams(showFullscreenButton: true), ); ``` -------------------------------- ### Install Application Target and Assets Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Installs the application executable, ICU data file, Flutter library, and bundled plugin libraries into the specified bundle directories. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### Install ICU Data File Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Installs the ICU data file to the data directory for runtime use. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library for Profile/Release Builds Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory, but only for Profile and Release configurations. ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Conditionally Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library only on non-Debug builds. This optimizes performance for release versions. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Create Custom Play Pause Button Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/README.md Use YoutubeValueBuilder to create custom controls. This example shows how to build a play/pause button that updates based on the player's state. The controller can be omitted if YoutubePlayerControllerProvider is used. ```dart YoutubeValueBuilder( controller: _controller, // This can be omitted, if using `YoutubePlayerControllerProvider` builder: (context, value) { return IconButton( icon: Icon( value.playerState == PlayerState.playing ? Icons.pause : Icons.play_arrow, ), onPressed: value.isReady ? () { value.playerState == PlayerState.playing ? context.ytController.pause() : context.ytController.play(); } : null, ); }, ); ``` -------------------------------- ### Get Available Playback Rates Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Retrieves the list of available playback rates for the current video, preparing it for platform-specific transmission. ```javascript function getAvailablePlaybackRates(){ return prepareDataForPlatform(player.getAvailablePlaybackRates()); } ``` -------------------------------- ### Get Playlist Data Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Retrieves data about the current playlist, preparing it for platform-specific transmission. ```javascript function getPlaylist() { return prepareDataForPlatform(player.getPlaylist()); } ``` -------------------------------- ### Get Video Data Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Retrieves data about the currently playing video, preparing it for platform-specific transmission. ```javascript function getVideoData() { return prepareDataForPlatform(player.getVideoData()); } ``` -------------------------------- ### Get Thumbnail URL Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Retrieve the thumbnail URL directly without creating a player widget. Specify video ID, quality, and format. ```dart final url = YoutubePlayerController.getThumbnail( videoId: '', quality: ThumbnailQuality.high, format: ThumbnailFormat.webp, ); ``` -------------------------------- ### Basic YouTube Player Implementation Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/README.md Initialize and display a YouTube player with basic configurations like auto-play and mute. Listen for the 'onReady' callback to attach listeners. ```dart YoutubePlayerController _controller = YoutubePlayerController( initialVideoId: 'iLnmTe5Q2Qw', flags: YoutubePlayerFlags( autoPlay: true, mute: true, ), ); YoutubePlayer( controller: _controller, showVideoProgressIndicator: true, progressIndicatorColor: Colors.amber, progressColors: const ProgressBarColors( playedColor: Colors.amber, handleColor: Colors.amberAccent, ), onReady: () { _controller.addListener(listener); }, ), ``` -------------------------------- ### Cross-Building Sysroot Configuration Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Sets up the sysroot and search paths for cross-building, ensuring correct library and include path resolution. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Initialize YoutubePlayerController Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/README.md Create a YoutubePlayerController with customizable parameters for playback and controls. Use loadVideoById for auto-play or cueVideoById for manual play. Load playlists similarly with loadPlaylist or cuePlaylist. ```dart final _controller = YoutubePlayerController( params: YoutubePlayerParams( mute: false, showControls: true, showFullscreenButton: true, ), ); _controller.loadVideoById(...); // Auto Play _controller.cueVideoById(...); // Manual Play _controller.loadPlaylist(...); // Auto Play with playlist _controller.cuePlaylist(...); // Manual Play with playlist ``` ```dart final _controller = YoutubePlayerController.fromVideoId( videoId: '', autoPlay: false, params: const YoutubePlayerParams(showFullscreenButton: true), ); ``` -------------------------------- ### Create and Initialize YoutubePlayerController Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Initialize the YoutubePlayerController with parameters to control video playback and UI elements. Load or cue a video by its ID or a playlist. ```dart final _controller = YoutubePlayerController( params: YoutubePlayerParams( mute: false, showControls: true, showFullscreenButton: true, privacyEnhancedMode: true, // uses youtube-nocookie.com (default) ), ); _controller.loadVideoById(videoId: ''); // ▶️ auto-play _controller.cueVideoById(videoId: ''); // ⏸️ ready but paused _controller.loadPlaylist(list: [...]); // ▶️ auto-play playlist _controller.cuePlaylist(list: [...]); // ⏸️ playlist, paused ``` -------------------------------- ### Include Application Build Rules Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Includes the CMakeLists.txt from the runner directory to build the application itself. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Prepare Data for Platform Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Formats data for transmission to the host application, stringifying it for web platforms if necessary. ```javascript function prepareDataForPlatform(data) { if(platform == 'android') return data; return JSON.stringify(data); } ``` -------------------------------- ### Player Initialization and Event Handling Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html This function is called by the YouTube API when it's ready. It initializes the player, sets up event listeners for various player states, and handles fullscreen for mobile platforms. ```javascript function onYouTubeIframeAPIReady() { player = new YT.Player("<>", { host: host, playerVars: <>, events: { onReady: function (event) { if (isMobile) handleFullScreenForMobilePlatform(); sendMessage('Ready', event); }, onStateChange: function (event) { clearInterval(timerId); sendMessage('StateChange', event.data); if (event.data == 1) { timerId = setInterval(function () { var state = { 'currentTime': player.getCurrentTime(), 'loadedFraction': player.getVideoLoadedFraction() }; sendMessage('VideoState', JSON.stringify(state)); }, 100); } }, onPlaybackQualityChange: function (event) { sendMessage('PlaybackQualityChange', event.data); }, onPlaybackRateChange: function (event) { sendMessage('PlaybackRateChange', event.data); }, onApiChange: function (event) { sendMessage('ApiChange', event.data); }, onError: function (event) { sendMessage('PlayerError', event.data); }, onAutoplayBlocked: function (event) { sendMessage('AutoplayBlocked', event.data); }, }, }); if (platform !== 'web') player.setSize(window.innerWidth, window.innerHeight); } ``` -------------------------------- ### Initialize and Display Youtube Player Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/README.md Shows how to initialize a YoutubePlayerController with a video ID and playback flags, and then embed the player in a Flutter widget tree. Customize the player's appearance and behavior using various properties. ```dart YoutubePlayerController _controller; @override void initState(){ _controller = YoutubePlayerController( initialVideoId: 'iLnmTe5Q2Qw', flags: YoutubePlayerFlags( mute: false, autoPlay: true, ), ); super.initState(); } @override Widget build(BuildContext context){ return YoutubePlayer( controller: _controller, showVideoProgressIndicator: true, videoProgressIndicatorColor: Colors.amber, progressColors: ProgressColors( playedColor: Colors.amber, handleColor: Colors.amberAccent, ), onReady: () { print('Player is ready.'); }, ); } ``` -------------------------------- ### Apply Standard Settings to Target Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Applies the standard build settings defined in the APPLY_STANDARD_SETTINGS function to the application target. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Runtime Path Configuration Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Configures the runtime path for bundled libraries, allowing them to be loaded from the 'lib/' directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### System Dependencies Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Finds and checks for the GTK+ 3.0 PkgConfig module, which is a system-level dependency. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This can be removed if the application requires different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Find System Dependencies with PkgConfig Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and check for required system libraries such as GTK, GLIB, and GIO. These are essential for Flutter's Linux integration. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Adds definitions to ensure Unicode is used for all projects. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Configure Flutter Library and Headers Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/flutter/CMakeLists.txt Defines the path to the Flutter library and its header files. It also sets up include directories and links against system libraries and the Flutter library itself. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Window Resize Handling Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Adjusts the player size to fit the window dimensions when the window is resized, ensuring responsiveness. ```javascript window.onresize = function () { if (player && platform !== 'web') player.setSize(window.innerWidth, window.innerHeight); }; ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Links necessary libraries and specifies include directories for the application. Application-specific dependencies should also be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Include Generated Plugin Build Rules Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Includes the CMake file that manages building plugins and adding them to the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Build Configuration Options Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Configures the build types (Debug, Profile, Release) based on whether the generator supports multi-configuration. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Playing Live Stream Videos Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/README.md Configure the YoutubePlayerController with `isLive: true` to enable the UI specifically designed for live stream videos. Customize the color using `liveUIColor`. ```dart YoutubePlayerController _controller = YoutubePlayerController( initialVideoId: 'iLnmTe5Q2Qw', flags: YoutubePLayerFlags( isLive: true, ), ); YoutubePlayer( controller: _controller, liveUIColor: Colors.amber, ), ``` -------------------------------- ### Message Handling from Host Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Listens for messages from the host application, parses them, and safely calls corresponding YouTube player methods or allowed global functions. ```javascript window.addEventListener('message', (event) => { try { var data = JSON.parse(event.data); if(data.function){ var rawFunction = data.function.replaceAll('<>', '"'); var result = _safeCall(rawFunction); if(data.key) { var message = {} message[data.key] = result var messageString = JSON.stringify(message); event.source.postMessage(messageString , '*'); } } } catch (e) { } }, false); ``` -------------------------------- ### Application Target Definition Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Defines the main application executable target, listing its source files including generated plugin registration. ```cmake # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Link Libraries Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Links the application target against the Flutter library and the PkgConfig::GTK target. ```cmake # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Initialize YouTube IFrame API Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html This script tag is essential for loading the YouTube IFrame Player API. It ensures that the API is ready before any player-related functions are called. ```javascript var tag = document.createElement("script"); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); ``` -------------------------------- ### Configure Player Parameters Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Customize player behavior and appearance using various parameters like mute, controls visibility, fullscreen button, privacy mode, loop, captions, and UI language. Use `copyWith` to modify existing parameter sets. ```dart final params = const YoutubePlayerParams(showControls: false); final updated = params.copyWith(mute: true); ``` -------------------------------- ### Web Entrypoint Configuration Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/web/index.html Configures the service worker and loads the Flutter entrypoint for web applications. This is essential for initializing the Flutter engine and running the app. ```javascript youtube\_player\_flutter\_example // The value below is injected by flutter build, do not touch. var serviceWorkerVersion = null; window.addEventListener('load', function(ev) { // Download main.dart.js \_flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, }, onEntrypointLoaded: function(engineInitializer) { engineInitializer.initializeEngine().then(function(appRunner) { appRunner.runApp(); }); } }); }); ``` -------------------------------- ### Use YoutubePlayerScaffold for Fullscreen Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/README.md Utilize YoutubePlayerScaffold when fullscreen playback is required. It provides a structure that accommodates the player and allows for custom UI elements. ```dart YoutubePlayerScaffold( controller: _controller, aspectRatio: 16 / 9, builder: (context, player) { return Column( children: [ player, Text('Youtube Player'), ], ); }, ) ``` -------------------------------- ### Include Flutter Library and Tool Build Rules Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Adds the Flutter managed directory as a subdirectory to include its build rules. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Specifies the minimum required CMake version and names the CXX project. ```cmake cmake_minimum_required(VERSION 3.14) project(youtube_player_flutter_example LANGUAGES CXX) ``` -------------------------------- ### Expose Controller with Provider Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Utilize YoutubePlayerControllerProvider to make the controller accessible to descendant widgets via context. This avoids prop drilling. The child widget tree can then access the controller using `context.ytController`. ```dart YoutubePlayerControllerProvider( controller: _controller, child: Scaffold( body: Column( children: [ YoutubePlayer(controller: _controller), const Controls(), // 🎛️ can call context.ytController inside ], ), ), ); ``` -------------------------------- ### Inherit Controller with Provider Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/README.md Use YoutubePlayerControllerProvider to make the controller accessible to descendant widgets. Access the controller using static methods or the controller property. ```dart YoutubePlayerControllerProvider( controller: _controller, child: Builder( builder: (context){ // Access the controller as: // `YoutubePlayerControllerProvider.of(context)` // or `controller.ytController`. }, ), ); ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/flutter/CMakeLists.txt This custom command executes the Flutter tool backend script to build the Flutter library and its headers. It uses a phony output to ensure the command runs on every build. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Standard Build Settings Function Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Defines a function to apply standard compilation settings like C++ standard, warning options, optimization levels, and NDEBUG definition. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build target to include version information. This allows the application to access version details at compile time. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Define Settings for Profile Build Mode Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Sets linker and compiler flags for the Profile build mode, typically inheriting from Release settings. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Define Executable Target Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner and lists all source files required for the application. Any new source files should be added here. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Generated Plugin Rules Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Includes the CMake script that manages the build rules for generated plugins. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Runtime Output Directory Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory, preventing users from running the unbundled copy. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Opt-in to Modern CMake Behaviors Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Explicitly enables modern CMake behaviors to prevent warnings with newer CMake versions. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Build Type Configuration Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already configured, and enforces a list of allowed build types. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### YouTube Player with FullScreen Support Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/README.md Wrap the YoutubePlayer widget with YoutubePlayerBuilder to enable full-screen mode. The builder provides the player widget to be included in your layout. ```dart YoutubePlayerBuilder( player: YoutubePlayer( controller: _controller, ), builder: (context, player){ return Column( children: [ // some widgets player, //some other widgets ], ); }, ), ``` -------------------------------- ### Migration from YoutubePlayerScaffold Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Update from the deprecated YoutubePlayerScaffold to the current YoutubePlayer widget. The new approach integrates fullscreen handling directly into YoutubePlayer, simplifying the structure. ```dart // ☠ Before (old way) YoutubePlayerScaffold( controller: _controller, builder: (context, player) { return Scaffold( body: Column(children: [player, const Controls()]), ); }, ) // ✅ After (new way) YoutubePlayerControllerProvider( controller: _controller, child: Scaffold( body: Column( children: [ YoutubePlayer(controller: _controller), const Controls(), ], ), ), ) ``` -------------------------------- ### Lazy Thumbnail Loading Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Use YoutubePlayerThumbnail for lists to display crisp thumbnails and defer WebView creation until tapped. This improves scrolling performance. Configure aspect ratio, thumbnail quality, and format. ```dart YoutubePlayerThumbnail( controller: YoutubePlayerController.fromVideoId(videoId: ''), aspectRatio: 16 / 9, thumbnailQuality: ThumbnailQuality.high, thumbnailFormat: ThumbnailFormat.webp, // Optional: bring your own play icon // playIcon: const Icon(Icons.play_circle, size: 64, color: Colors.white), ) ``` -------------------------------- ### Use YoutubePlayer Widget Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/README.md Embed the YoutubePlayer widget in your layout when fullscreen support is not needed. Configure the aspect ratio for proper display. ```dart YoutubePlayer( controller: _controller, aspectRatio: 16 / 9, ); ``` -------------------------------- ### Custom Controls with YoutubeValueBuilder Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Build custom playback controls using YoutubeValueBuilder, which rebuilds on player state changes. Access the controller via `context.ytController` to control playback (play/pause). ```dart YoutubeValueBuilder( controller: _controller, // omit if using YoutubePlayerControllerProvider builder: (context, value) { return IconButton( icon: Icon( value.playerState == PlayerState.playing ? Icons.pause : Icons.play_arrow, ), onPressed: value.isReady ? () { value.playerState == PlayerState.playing ? context.ytController.pause() : context.ytController.play(); } : null, ); }, ); ``` -------------------------------- ### Define Standard Compilation Settings Function Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt A function to apply common compilation features, options, and definitions to a target. Use with caution, as plugins also use this. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Define Executable Binary Name Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/CMakeLists.txt Sets the name of the executable file for the application. This can be changed to alter the on-disk name. ```cmake set(BINARY_NAME "youtube_player_flutter_example") ``` -------------------------------- ### Add Flutter Build Dependencies Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Ensures that the Flutter build artifacts are assembled before the main application target. This step is crucial for the Flutter build process and must not be removed. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Define list_prepend CMake Function Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a given list. It is used as a workaround for the missing list(TRANSFORM ... PREPEND ...) command in CMake version 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Project and Executable Naming Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, and the executable name for the application. This executable name is used by `flutter run`. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "youtube_player_flutter_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "np.com.sarbagyastha.youtube_player_flutter_example") ``` -------------------------------- ### Generic Message Sending Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html A wrapper function to send structured messages containing player state or events to the host application. ```javascript function sendMessage(key, data) { var message = {}; message[key] = data; message['playerId'] = '<>'; var messageString = JSON.stringify(message); sendPlatformMessage(messageString); } ``` -------------------------------- ### Handle Fullscreen for Mobile Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Attempts to hook into the YouTube player's fullscreen button to send a message when pressed, specifically for mobile platforms. ```javascript function handleFullScreenForMobilePlatform() { try { var ytFrame = document.getElementsByTagName('iframe')[0].contentWindow.document; var fsButton = ytFrame.getElementsByClassName('ytp-fullscreen-button ytp-button')[0]; if(fsButton != null) { var fsButtonCopy = fsButton.cloneNode(true); fsButton.replaceWith(fsButtonCopy); fsButtonCopy.onclick = function(e) { e.stopPropagation(); e.preventDefault(); sendMessage('FullscreenButtonPressed', ''); }; } } catch (e) { console.warn('youtube_player: fullscreen button setup failed', e); } } ``` -------------------------------- ### Customizing Player Controls Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/README.md Customize the bottom action bar of the YouTube player using the `bottomActions` property. This allows for inclusion of widgets like `CurrentPosition`, `ProgressBar`, and `TotalDuration`. ```dart YoutubePlayer( controller: _controller, bottomActions: [ CurrentPosition(), ProgressBar(isExpanded: true), TotalDuration(), ], ), ``` -------------------------------- ### Flutter Assemble Dependency Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/linux/CMakeLists.txt Ensures that the 'flutter_assemble' target is built before the application target, which is required for the Flutter toolchain. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Safe Function Execution Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html A utility function to safely execute methods on the YT.Player object or a limited set of global functions, preventing arbitrary code execution. ```javascript function _safeCall(rawFunction) { var playerMatch = rawFunction.match(/^player\.(\w+)\((\[\s\S\]*)\);?$/); if (playerMatch) { var fn = playerMatch[1]; var argsStr = playerMatch[2].trim(); if (typeof player[fn] !== 'function') throw new Error('Unknown player method: ' + fn); return argsStr ? player[fn](JSON.parse(argsStr)) : player[fn](); } var globalAllowlist = { getVideoData: getVideoData, getPlaylist: getPlaylist, getAvailablePlaybackRates: getAvailablePlaybackRates }; var globalMatch = rawFunction.match(/^(\w+)\(\);?$/); if (globalMatch && globalMatch[1] in globalAllowlist) { return globalAllowlist[globalMatch[1]](); } throw new Error('Disallowed function: ' + rawFunction); } ``` -------------------------------- ### Platform-Specific Message Sending Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/assets/player.html Sends messages to the host application, adapting the method based on the detected platform (Android, iOS, macOS, web). ```javascript function sendPlatformMessage(message) { switch(platform) { case 'android': <>.postMessage(message); break; case 'ios': case 'macos': <>.postMessage(message, '*'); break; case 'web': window.parent.postMessage(message, '*'); break; } } ``` -------------------------------- ### Dispose YoutubePlayerController Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Ensure the YoutubePlayerController is properly disposed of when the widget is removed from the tree to prevent memory leaks. ```dart @override void dispose() { _controller.close(); super.dispose(); } ``` -------------------------------- ### Embed YoutubePlayer Widget Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_iframe/README.md Integrate the YoutubePlayer widget into your Flutter widget tree. Configure aspect ratio and auto-fullscreen behavior. ```dart YoutubePlayer( controller: _controller, aspectRatio: 16 / 9, autoFullScreen: true, // 📱 auto-enters fullscreen on landscape rotation ) ``` -------------------------------- ### Convert YouTube URL to Video ID Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/README.md Use `convertUrlToId()` to transform YouTube URLs into their corresponding video IDs. This is useful for directly embedding videos when only a URL is available. ```dart String videoId; videoId = YoutubePlayer.convertUrlToId("https://www.youtube.com/watch?v=BBAyRBTfsOU"); print(videoId); // BBAyRBTfsOU ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/sarbagyastha/youtube_player_flutter/blob/develop/packages/youtube_player_flutter/example/windows/runner/CMakeLists.txt Disables Windows-specific macros like NOMINMAX that might conflict with C++ standard library functions. This ensures cleaner C++ code. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.