npaw_forge_media_kit 10.3.0
npaw_forge_media_kit: ^10.3.0 copied to clipboard
NPAW Forge adapter for the media_kit Flutter player: reports typed playback lifecycle plus mpv-level QoS (bitrate, fps, dropped frames) to the Forge core.
example/lib/main.dart
// Copyright (C) NPAW - All Rights Reserved
//
// This source code is protected under international copyright law. All rights
// reserved and protected by the copyright holders. This file is confidential and
// only available to authorized individuals with the permission of the copyright
// holders. If you encounter this file and do not have permission, please contact
// the copyright holders and delete this file.
//
//
// @author: Victor Soto <victor.soto@nicepeopleatwork.com>
// @description: NPAW Forge media_kit example app playing a sample stream with automatic analytics.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:npaw_forge/npaw_forge.dart';
import 'package:npaw_forge_media_kit/npaw_forge_media_kit.dart';
/// Demo account; override with --dart-define=FORGE_ACCOUNT_CODE=yourAccount.
const String accountCode = String.fromEnvironment(
'FORGE_ACCOUNT_CODE',
defaultValue: 'npawdemodev',
);
/// Ingest endpoint; point smoke runs at stage, never production.
const String lmaEndpoint = String.fromEnvironment('FORGE_LMA_ENDPOINT');
/// Opt-in diagnostics printer for smoke evidence
/// (--dart-define=FORGE_DEBUG_DIAGNOSTICS=true).
const bool debugDiagnostics =
bool.fromEnvironment('FORGE_DEBUG_DIAGNOSTICS', defaultValue: false);
const String sampleStream = String.fromEnvironment(
'FORGE_SAMPLE_STREAM',
defaultValue: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
);
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
final forge = await NpawForge.start(
ForgeConfig(
accountCode: accountCode,
appName: 'npaw-forge-media-kit-example',
lmaEndpoint: lmaEndpoint.isEmpty ? null : lmaEndpoint,
logLevel: 'info',
),
);
if (debugDiagnostics) {
forge.events.listen((event) => debugPrint('forge event: ${event.raw}'));
}
WidgetsBinding.instance.addObserver(ForgeLifecycleObserver(forge));
runApp(ExampleApp(forge: forge));
}
class ExampleApp extends StatefulWidget {
const ExampleApp({required this.forge, super.key});
final NpawForge forge;
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
late final Player player = Player();
late final VideoController controller = VideoController(player);
ForgeMediaKitAttachment? attachment;
Timer? _qosTimer;
@override
void initState() {
super.initState();
_start();
}
Future<void> _start() async {
attachment = await attachMediaKitPlayer(
widget.forge,
player,
metadata: const ContentMetadata(title: 'media_kit sample stream'),
);
await player.open(Media(sampleStream));
if (debugDiagnostics) {
_qosTimer = Timer.periodic(const Duration(seconds: 5), (_) {
final json = attachment?.adapter.metadata().toJson();
debugPrint('forge qos sample: bitrate=${json?['bitrate']} '
'droppedFrames=${json?['droppedFrames']} '
'rendition=${json?['rendition']} qos=${json?['qos']}');
});
}
}
@override
void dispose() {
_qosTimer?.cancel();
attachment?.dispose();
player.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Forge media_kit example',
home: Scaffold(
appBar: AppBar(title: const Text('Forge media_kit example')),
body: Center(
child: AspectRatio(
aspectRatio: 16 / 9,
child: Video(controller: controller),
),
),
),
);
}
}