bestplayer 0.0.1 copy "bestplayer: ^0.0.1" to clipboard
bestplayer: ^0.0.1 copied to clipboard

A new Flutter plugin which contains jwplayer with Google Ima Ads.

example/lib/main.dart

import 'package:bestplayer/bestplayer-adschedule.model.dart';
import 'package:bestplayer/bestplayer-vod.model.dart';
import 'package:bestplayer/bestplayer_controller.dart';
import 'package:bestplayer/bestplayer_event_type.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:bestplayer/bestplayer.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final controller = BestplayerController.instance;

  final iosLicense = "YOUR IOS LICENSE KEY HERE";
  final androidLicense = "YOUR ANDROID LICENSE KEY HERE";

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

  void listener(event) {
    // Hndle events

    switch (event.type) {
      case BestPlayerEventType.ready:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.progress:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.play:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.pause:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.finish:
        {
          break;
        }
      case BestPlayerEventType.adPlay:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.adComplete:
        {
          setState(() {});
          break;
        }
      case BestPlayerEventType.error:
        {
          break;
        }
    }
  }

  Future<void> initPlayer() async {
    Timer(const Duration(seconds: 5), () {
      final vod = BestplayerVodModel(
        file: "https://cdn.jwplayer.com/manifests/NjhRveIM.m3u8",
        title: "TCN Top20 Countdown Ep 509",
        mediaId: "NjhRveIM",
      );

      final adSchedule = BestPlayerAdScheduleModel(
        tag:
            "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=",
        offset: "pre",
      );

      vod.setAdvertisementConfig([adSchedule]);

      controller.setupDataSource(vod);

      controller.addListener(listener);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.black,
        body: Center(
          child: Column(
            children: [
              Expanded(
                child: Stack(
                  children: [
                    Align(
                      alignment: Alignment.topLeft,
                      child: SizedBox(
                        width: 500,
                        height: 300,
                        child: BestPlayer(
                          androidLicense: androidLicense,
                          iosLicense: iosLicense,
                        ),
                      ),
                    ),
                    // if (controller.isReady)
                    Align(
                      alignment: Alignment.bottomLeft,
                      child: Container(
                        width: 500,
                        height: 200,
                        color: Colors.white,
                        child: Column(
                          children: [
                            Text("DURATION: ${controller.duration.inSeconds}"),
                            Text("POSITION: ${controller.position.inSeconds}"),
                            Text(
                                "PLAYING: ${controller.isPlaying ? "TRUE" : "FALSE"}"),
                            Text(
                                "READY: ${controller.isReady ? "TRUE" : "FALSE"}"),
                            Text(
                                "AD PLAYING: ${controller.isAdPlaying ? "TRUE" : "FALSE"}"),
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
110
pub points
0%
popularity

Publisher

unverified uploader

A new Flutter plugin which contains jwplayer with Google Ima Ads.

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bestplayer