cp_hls_video_player 0.0.1
cp_hls_video_player: ^0.0.1 copied to clipboard
Adaptive HLS Video Player
example/lib/main.dart
import 'package:cp_hls_video_player/cp_hls_video_player.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final CPHlsVideoPlayerController _controller = CPHlsVideoPlayerController();
@override
initState(){
super.initState();
_controller.setSeekStartListener((position, totalDuration) {
debugPrint("***********> Seek start> Position: ${position.inSeconds}, Total: ${totalDuration.inSeconds}");
});
_controller.setSeekEndListener((position, totalDuration) {
debugPrint("***********> Seek end> Position: ${position.inSeconds}, Total: ${totalDuration.inSeconds}");
});
_controller.setStateListener((isPlaying, isEnded, currentPosition, totalDuration) {
debugPrint("***********> State changed> IsPlaying: $isPlaying, IsEnded: $isEnded Position: ${currentPosition.inSeconds}, Total: ${totalDuration.inSeconds}");
});
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_controller.loadHLSVideo("https://bitmovin-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8");
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
top: MediaQuery.of(context).orientation == Orientation.portrait,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
CPHlsVideoPlayer(
controller: _controller,
),
],
),
),
);
}
}