### Start Method Source: https://github.com/surgeonix/flyleaf/wiki/Engine Initiates the startup process of the system. ```APIDOC ## Start Method ### Description Initiates the startup sequence for the application or a specific module. ### Method POST ### Endpoint /start ``` -------------------------------- ### Initialize Flyleaf Engine and Host in WinUI 3 Source: https://context7.com/surgeonix/flyleaf/llms.txt Demonstrates the setup of the Flyleaf engine in App.xaml.cs and the integration of the FlyleafHost control within a FullScreenContainer in WinUI 3. It includes configuration for FFmpeg paths and UI refresh settings. ```csharp public partial class App : Application { public App() { InitializeComponent(); Engine.Start(new EngineConfig() { FFmpegPath = @"C:\Flyleaf\FFmpeg", FFmpegDevices = false, #if DEBUG FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Warn, LogLevel = LogLevel.Debug, LogOutput = ":debug", #else FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Quiet, LogLevel = LogLevel.Quiet, #endif UIRefresh = true, UIRefreshInterval = 250 }); } } ``` ```xml ``` ```csharp public sealed partial class MainWindow : Window { public Player Player { get; set; } public Config Config { get; set; } public MainWindow() { Config = new Config(); Config.Video.BackgroundColor = System.Windows.Media.Colors.DarkGray; Player = new Player(Config); InitializeComponent(); rootGrid.DataContext = this; FSC.FullScreenEnter += (o, e) => flyleafHost.KFC.Focus(FocusState.Keyboard); FSC.FullScreenExit += (o, e) => Task.Run(() => { Thread.Sleep(10); Utils.UIInvoke(() => flyleafHost.KFC.Focus(FocusState.Keyboard)); }); } } ``` -------------------------------- ### Initialize Flyleaf Engine in WinUI 3 App Source: https://github.com/surgeonix/flyleaf/wiki/Home Configures and starts the Flyleaf Engine upon application launch. It includes settings for FFmpeg path, logging levels (debug/release), and UI refresh intervals. Ensure FFmpeg is installed at the specified path. ```csharp using FlyleafLib; using Microsoft.UI.Xaml; namespace FlyleafSample; public partial class App : Application { public App() { InitializeComponent(); Engine.Start(new EngineConfig() { FFmpegPath = @"C:\\Flyleaf\\FFmpeg", FFmpegDevices = false, // Prevents loading avdevice/avfilter dll files. Enable it only if you plan to use dshow/gdigrab etc. #if RELEASE FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Quiet, LogLevel = LogLevel.Quiet, #else FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Warn, LogLevel = LogLevel.Debug, LogOutput = ":debug", //LogOutput = ":console", //LogOutput = @"C:\\Flyleaf\\Logs\\flyleaf.log", #endif //PluginsPath = @"C:\\Flyleaf\\Plugins", UIRefresh = false, // Required for Activity, BufferedDuration, Stats in combination with Config.Player.Stats = true UIRefreshInterval = 250, // How often (in ms) to notify the UI UICurTimePerSecond = true, // Whether to notify UI for CurTime only when it's second changed or by UIRefreshInterval }); } protected override void OnLaunched(LaunchActivatedEventArgs args) { m_window = new MainWindow(); m_window.Activate(); } private Window m_window; } ``` -------------------------------- ### Initialize Flyleaf Engine Source: https://github.com/surgeonix/flyleaf/wiki/Home Configures and starts the Flyleaf engine in the application entry point. This includes setting FFmpeg paths, log levels, and UI refresh settings. ```csharp using FlyleafLib; namespace FlyleafSample { internal static class Program { [STAThread] static void Main() { Engine.Start(new EngineConfig() { FFmpegPath = @"C:\Flyleaf\FFmpeg", FFmpegDevices = false, #if RELEASE FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Quiet, LogLevel = LogLevel.Quiet, #else FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Warn, LogLevel = LogLevel.Debug, LogOutput = ":debug", #endif UIRefresh = false, UIRefreshInterval = 250, UICurTimePerSecond = true, }); ApplicationConfiguration.Initialize(); Application.Run(new Form1()); } } } ``` -------------------------------- ### FlyleafHost Control (WPF) Source: https://context7.com/surgeonix/flyleaf/llms.txt Integration guide for the FlyleafHost DPI-aware rendering surface in WPF applications. ```APIDOC ## FlyleafHost Control (WPF) ### Description FlyleafHost provides a rendering surface for WPF applications, supporting overlays and detached modes. ### Method N/A (XAML Control) ### Parameters - **Player** (Player) - Required - The Flyleaf Player instance. - **AttachedDragMove** (string) - Optional - Drag move behavior. - **KeepRatioOnResize** (bool) - Optional - Maintains aspect ratio on window resize. ### Request Example ### Response - **FlyleafHost** (UIElement) - The rendered video surface with optional overlay support. ``` -------------------------------- ### GET /player/open/clipboard Source: https://github.com/surgeonix/flyleaf/wiki/Player (Open) Opens a media source directly from the system clipboard. ```APIDOC ## GET /player/open/clipboard ### Description Retrieves a URL from the system clipboard and attempts to open it as a media source in the player. ### Method GET ### Endpoint /player/open/clipboard ### Response #### Success Response (200) - **message** (string) - Confirmation that the clipboard content is being processed. ``` -------------------------------- ### Setup Flyleaf Player and UI in WinUI 3 MainWindow Source: https://github.com/surgeonix/flyleaf/wiki/Home Initializes the Flyleaf Player and its configuration within the MainWindow. It also sets up event handlers for full-screen mode to ensure proper keyboard focus management. The DataContext is set to allow binding UI elements to the player. ```csharp using FlyleafLib; using FlyleafLib.MediaPlayer; using Microsoft.UI.Xaml; using System.Threading.Tasks; using System.Threading; namespace FlyleafSample; public sealed partial class MainWindow : Window { public Player Player { get; set; } public Config Config { get; set; } public MainWindow() { Config = new Config(); Config.Video.BackgroundColor = System.Windows.Media.Colors.DarkGray; Player = new Player(Config); InitializeComponent(); rootGrid.DataContext = this; // Keyboard focus fix FSC.FullScreenEnter += (o, e) => flyleafHost.KFC.Focus(FocusState.Keyboard); FSC.FullScreenExit += (o, e) => Task.Run(() => { Thread.Sleep(10); Utils.UIInvoke(() => flyleafHost.KFC.Focus(FocusState.Keyboard)); }); } } ``` -------------------------------- ### Custom Plugin Development in C# for Flyleaf Source: https://context7.com/surgeonix/flyleaf/llms.txt Demonstrates how to create custom plugins for Flyleaf using C#. This includes examples for suggesting video and audio streams based on custom criteria, and defining plugin-specific options. Compiled plugin DLLs should be placed in the 'Plugins' directory. ```csharp using FlyleafLib.MediaFramework.MediaStream; using FlyleafLib.Plugins; using System.Collections.ObjectModel; /// /// Custom Video Stream Suggester - selects highest resolution with best FPS /// public class CustomVideoStreamSuggester : PluginBase, ISuggestVideoStream { // Higher priority takes precedence (default StreamSuggester has priority 0) public new int Priority { get; set; } = 1; public VideoStream SuggestVideo(ObservableCollection streams) { return streams .OrderByDescending(s => s.Height) .ThenByDescending(s => s.FPS) .FirstOrDefault(); } } /// /// Custom Audio Stream Suggester - prefers specific language and codec /// public class CustomAudioStreamSuggester : PluginBase, ISuggestAudioStream { public new int Priority { get; set; } = 1; public AudioStream SuggestAudio(ObservableCollection streams, VideoStream videoStream) { // Prefer English AAC audio var preferred = streams .Where(s => s.Language?.ISO639_1 == "en") .Where(s => s.Codec?.Contains("aac") == true) .OrderByDescending(s => s.BitRate) .FirstOrDefault(); return preferred ?? streams.FirstOrDefault(); } } /// /// Custom plugin options example /// public class MyPlugin : PluginBase { public override Dictionary GetDefaultOptions() { return new Dictionary { { "ApiKey", "" }, { "MaxResults", "10" }, { "PreferHD", "true" } }; } // Access options via: Config.Plugins["MyPlugin"]["ApiKey"] } // Place compiled plugin DLLs in the Plugins directory // Structure: Plugins/MyPlugin/MyPlugin.dll ``` -------------------------------- ### Initialize Flyleaf Engine in App.xaml.cs Source: https://github.com/surgeonix/flyleaf/wiki/Home Configures and starts the Flyleaf engine during application startup. It sets paths for FFmpeg and defines logging levels based on build configuration. ```csharp using FlyleafLib; using System.Windows; namespace FlyleafSample { public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Engine.Start(new EngineConfig() { FFmpegPath = @"C:\Flyleaf\FFmpeg", FFmpegDevices = false, #if RELEASE FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Quiet, LogLevel = LogLevel.Quiet, #else FFmpegLogLevel = Flyleaf.FFmpeg.LogLevel.Warn, LogLevel = LogLevel.Debug, LogOutput = ":debug", #endif UIRefresh = false, UIRefreshInterval = 250, UICurTimePerSecond = true }); } } } ``` -------------------------------- ### Download Media Streams with Flyleaf Downloader in C# Source: https://context7.com/surgeonix/flyleaf/llms.txt This C# code demonstrates how to use the Flyleaf Downloader class to download media streams to local files. It covers initializing the engine, configuring downloader settings such as buffer duration and preferred video resolution, and setting up event handlers for download progress and completion. The example also shows how to open a media stream, list available video and audio streams, and initiate the download process. ```csharp using FlyleafLib; using FlyleafLib.MediaFramework.MediaContext; // Initialize Engine Engine.Start(new EngineConfig() { FFmpegPath = ":FFmpeg", PluginsPath = ":Plugins" }); // Configure downloader Config config = new Config(); config.Demuxer.FormatOptToUnderlying = true; // Pass query params for HLS sessions config.Demuxer.BufferDuration = 60 * 1000 * 10000; // 60 seconds buffer config.Demuxer.ReadTimeout = 60 * 1000 * 10000; // 60 seconds timeout config.Video.MaxVerticalResolutionCustom = 1080; // Prefer 1080p streams // Create downloader Downloader downloader = new Downloader(config); // Event handlers downloader.PropertyChanged += (s, e) => { switch (e.PropertyName) { case "CurTime": case "Duration": var cur = TimeSpan.FromTicks(downloader.CurTime); var dur = TimeSpan.FromTicks(downloader.Duration); Console.WriteLine($"Progress: {cur:hh\:mm\:ss} / {dur:hh\:mm\:ss}"); break; case "DownloadPercentage": Console.WriteLine($"Downloaded: {downloader.DownloadPercentage:F1}%"); break; } }; downloader.DownloadCompleted += (s, success) => { if (success) Console.WriteLine(downloader.DownloadPercentage == 100 ? "Download completed!" : "Download completed (partial)"); else Console.WriteLine("Download failed!"); }; // Open media string error = downloader.Open("https://example.com/video.mp4"); if (error != null) { Console.WriteLine($"Open error: {error}"); return; } // List available streams Console.WriteLine("Video Streams:"); foreach (var stream in downloader.DecCtx.VideoDemuxer.VideoStreams) Console.WriteLine($" {stream.Width}x{stream.Height} @ {stream.FPS}fps ({stream.Codec})"); Console.WriteLine("Audio Streams:"); foreach (var stream in downloader.DecCtx.VideoDemuxer.AudioStreams) Console.WriteLine($" {stream.Codec} {stream.SampleRate}Hz {stream.Channels}ch"); // Start download string filename = @"C:\Downloads\video.mp4"; downloader.Download(ref filename, useRecommendedExtension: true); // To stop download // downloader.Dispose(); ``` -------------------------------- ### Configuring Key and Mouse Bindings in Flyleaf Source: https://context7.com/surgeonix/flyleaf/llms.txt Shows how to customize keyboard shortcuts and mouse bindings for Flyleaf player control. It includes examples of default bindings and how to add custom actions, such as taking a snapshot with a specific key press. ```csharp using FlyleafLib; using FlyleafLib.MediaPlayer; Config config = new Config(); // Default key bindings (can be customized) // Playback // O or Drag & Drop - Open // Ctrl + C/V - Copy/Paste URL // P or Space - Toggle Play/Pause // Ctrl + Q - Stop // Left/Right - Seek Backward/Forward // Ctrl + Left/Right - Seek Backward2/Forward2 // -/+/0 - Speed Down/Up/Reset // Backspace - Toggle Reverse Playback // F or Double-click - Toggle Fullscreen // Escape - Exit Fullscreen // Audio // Shift + A - Toggle Audio // Up/Down - Volume Up/Down // M - Toggle Mute // [/] - Audio Delay +/- // Ctrl + [/] - Audio Delay2 +/- // Video // Shift + V - Toggle Video // Ctrl + H - Toggle Video Acceleration // Ctrl + R - Toggle Recording // R - Toggle Keep/Fill Ratio // Ctrl + T - Take Snapshot // Shift + Left/Right - Previous/Next Frame // Ctrl + +/- - Zoom In/Out // Ctrl + Drag - Pan // Shift + MouseWheel - Rotate // Subtitles // Shift + S - Toggle Subtitles // ;/' - Subtitles Delay +/- // Ctrl + ;/' - Subtitles Delay2 +/- // Custom key binding config.Player.KeyBindings.Enabled = true; config.Player.KeyBindings.FlyleafHostEnabled = true; // Add custom action Player player = new Player(config); player.Host?.KeyDown += (s, e) => { if (e.Key == System.Windows.Input.Key.F5) { player.TakeSnapshotToFile(); e.Handled = true; } }; ``` -------------------------------- ### WPF FlyleafHost with Style Template Source: https://github.com/surgeonix/flyleaf/wiki/FlyleafHost This WPF example demonstrates how to apply a style template to the FlyleafHost control. The 'OverlayTemplate' defined within the style is automatically transferred to the Overlay Window, allowing for customized visual appearance and behavior of the overlay content. This requires the 'FlyleafLib' assembly and 'FlyleafLib.Controls.WPF' namespace. ```xml