init static method
Future<void>
init({
- String? ip,
- int? port,
- int maxMemoryCacheSize = 100,
- int maxStorageCacheSize = 1024,
- bool logPrint = false,
- int segmentSize = 2,
- int maxConcurrentDownloads = 8,
- UrlMatcher? urlMatcher,
- HttpClientBuilder? httpClientBuilder,
Initializes the video proxy server and related components.
ip
: Optional IP address for the proxy server to bind.
port
: Optional port number for the proxy server to listen on.
maxMemoryCacheSize
: Maximum memory cache size in MB (default: 100).
maxStorageCacheSize
: Maximum storage cache size in MB (default: 1024).
logPrint
: Enables or disables logging output (default: false).
segmentSize
: Size of each video segment in MB (default: 2).
maxConcurrentDownloads
: Maximum number of concurrent downloads (default: 8).
urlMatcher
: Optional custom URL matcher for video URL filtering.
httpClientBuilder
: Optional custom HTTP client builder for creating HTTP clients.
Implementation
static Future<void> init({
String? ip,
int? port,
int maxMemoryCacheSize = 100,
int maxStorageCacheSize = 1024,
bool logPrint = false,
int segmentSize = 2,
int maxConcurrentDownloads = 8,
UrlMatcher? urlMatcher,
HttpClientBuilder? httpClientBuilder,
}) async {
// Set global configuration values for cache sizes and segment size.
Config.memoryCacheSize = maxMemoryCacheSize * Config.mbSize;
Config.storageCacheSize = maxStorageCacheSize * Config.mbSize;
Config.segmentSize = segmentSize * Config.mbSize;
// Enable or disable logging.
Config.logPrint = logPrint;
// Initialize and start the local proxy server.
_localProxyServer = LocalProxyServer(ip: ip, port: port);
await _localProxyServer.start();
// Create the HLS playlist parser instance.
hlsPlaylistParser = HlsPlaylistParser.create();
// Initialize the download manager with the specified concurrency.
downloadManager = DownloadManager(maxConcurrentDownloads);
// Set the URL matcher implementation (custom or default).
urlMatcherImpl = urlMatcher ?? UrlMatcherDefault();
// Set the HTTP client builder
httpClientBuilderImpl = httpClientBuilder ?? HttpClientDefault();
}