byteark_player_flutter 1.1.6 copy "byteark_player_flutter: ^1.1.6" to clipboard
byteark_player_flutter: ^1.1.6 copied to clipboard

ByteArkPlayerFlutter is a Flutter plugin for the ByteArk Player, designed to enable seamless video playback and advanced player management within your Flutter applications.

example/lib/main.dart

import 'package:byteark_player_flutter/data/byteark_player_license_key.dart';
import 'package:byteark_player_flutter/domain/byteark_player_listener.dart';
import 'package:byteark_player_flutter_example/demo/player_lighthouse_screen.dart';
import 'package:byteark_player_flutter_example/demo/player_playlist_screen.dart';
import 'package:byteark_player_flutter_example/demo/player_vertical_screen.dart';
import 'package:flutter/material.dart';
import 'package:byteark_player_flutter/data/byteark_player_config.dart';
import 'package:byteark_player_flutter/data/byteark_player_item.dart';
import 'package:byteark_player_flutter/presentation/byteark_player.dart';

void main() {
  runApp(const PlayerLighthouseScreen());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // Declare required variables
  late ByteArkPlayerItem _item;
  late ByteArkPlayerConfig _config;
  late ByteArkPlayerListener _listener;
  late ByteArkPlayer _player;

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

    // Step 1: Create a listener to handle player and ad events
    _listener = ByteArkPlayerListener(
      onPlayerReady: () {
        debugPrint("Player is ready.");
      },
      onAdsStart: (data) {
        debugPrint("Ad started. Data: ${data.toMap()}");
      },
    );

    // Step 2: Define the video source using ByteArkPlayerItem
    _item = ByteArkPlayerItem(
      url:
          "https://byteark-playertzxedwv.stream-playlist.byteark.com/streams/TZyZheqEJUwC/playlist.m3u8",
    );

    // Step 3: Configure the player using ByteArkPlayerConfig
    _config = ByteArkPlayerConfig(
      // Optional : Set up ads if needed.
      adsSettings: ByteArkAdsSettings(
        adTagUrl:
            "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=",
      ),
      licenseKey: ByteArkPlayerLicenseKey(
        android: "ANDROID_KEY", // Replace with your Android license key
        iOS: "IOS_KEY", // Replace with your iOS license key
      ),
      playerItem: _item,
    );

    // Step 4: Initialize the ByteArkPlayer with the config and listener
    _player = ByteArkPlayer(
      playerConfig: _config,
      listener: _listener,
    );
  }

  @override
  void dispose() {
    // Clean up player instance.
    _player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ByteArk Player Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('ByteArk Player Demo'),
          centerTitle: true,
        ),
        body: Column(
          children: [
            // Step 5: Embed the player into your UI using AspectRatio
            AspectRatio(
              aspectRatio: 16 / 9,
              child: _player,
            ),
            const SizedBox(height: 16),
            // Optional: Add controls to interact with the player
            ElevatedButton(
              onPressed: () => _player.pause(),
              child: const Text("Pause"),
            ),
          ],
        ),
      ),
    );
  }
}
5
likes
130
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

ByteArkPlayerFlutter is a Flutter plugin for the ByteArk Player, designed to enable seamless video playback and advanced player management within your Flutter applications.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface, uuid

More

Packages that depend on byteark_player_flutter

Packages that implement byteark_player_flutter