npaw_forge_theoplayer 10.0.4 copy "npaw_forge_theoplayer: ^10.0.4" to clipboard
npaw_forge_theoplayer: ^10.0.4 copied to clipboard

NPAW Forge adapter for the THEOplayer Flutter SDK: reports the typed playback lifecycle plus active-quality QoS facts 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 THEOplayer example app playing a sample stream with automatic analytics.

import 'package:flutter/material.dart';
import 'package:npaw_forge/npaw_forge.dart';
import 'package:npaw_forge_theoplayer/npaw_forge_theoplayer.dart';
import 'package:theoplayer/theoplayer.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');

/// THEOplayer license, a runtime secret: --dart-define=THEO_LICENSE=...
/// Never commit a license value.
const String theoLicense = String.fromEnvironment('THEO_LICENSE');

const String sampleStream = String.fromEnvironment(
  'FORGE_SAMPLE_STREAM',
  defaultValue: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
);

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final forge = await NpawForge.start(
    ForgeConfig(
      accountCode: accountCode,
      appName: 'npaw-forge-theoplayer-example',
      lmaEndpoint: lmaEndpoint.isEmpty ? null : lmaEndpoint,
      logLevel: 'info',
    ),
  );
  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 THEOplayer player = THEOplayer(
    theoPlayerConfig: THEOplayerConfig(
      license: theoLicense.isEmpty ? null : theoLicense,
    ),
    onCreate: _onPlayerCreated,
  );
  ForgeTheoplayerAttachment? attachment;

  @override
  void initState() {
    super.initState();
    _attach();
  }

  Future<void> _attach() async {
    attachment = await attachTheoplayer(
      widget.forge,
      player,
      metadata: const ContentMetadata(title: 'THEOplayer sample stream'),
    );
  }

  void _onPlayerCreated() {
    player.source = SourceDescription(
      sources: [TypedSource(src: sampleStream)],
    );
    player.autoplay = true;
  }

  @override
  void dispose() {
    attachment?.dispose();
    player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Forge THEOplayer example',
      home: Scaffold(
        appBar: AppBar(title: const Text('Forge THEOplayer example')),
        body: Center(
          child: AspectRatio(
            aspectRatio: 16 / 9,
            child: player.view,
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
641
downloads

Publisher

unverified uploader

Weekly Downloads

NPAW Forge adapter for the THEOplayer Flutter SDK: reports the typed playback lifecycle plus active-quality QoS facts to the Forge core.

Homepage
Repository

License

unknown (license)

Dependencies

flutter, npaw_forge, theoplayer

More

Packages that depend on npaw_forge_theoplayer