aws_ivs_player 0.1.2
aws_ivs_player: ^0.1.2 copied to clipboard
A modern AWS IVS Player SDK implementation for Flutter with cross-platform support for live and on-demand video streaming.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:aws_ivs_player/aws_ivs_player.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'IVS Player Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'IVS Player Example'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late IvsPlayerController _controller;
final TextEditingController _urlController = TextEditingController();
Key _playerKey = UniqueKey();
late bool _isStopped;
final bool _autoPlayDefault = false;
final bool _showOverlayControls = false;
late bool _currentAutoPlay;
// Test stream URL
final String testUrl =
'https://fcc3ddae59ed.us-west-2.playback.live-video.net/api/video/v1/us-west-2.893648527354.channel.DmumNckWFTqz.m3u8';
@override
void initState() {
super.initState();
_controller = IvsPlayerController();
_urlController.text = testUrl;
_currentAutoPlay = _autoPlayDefault;
_isStopped = !_currentAutoPlay;
}
@override
void dispose() {
_controller.dispose();
_urlController.dispose();
super.dispose();
}
void _stopPlayer() {
_controller.stop();
setState(() {
_currentAutoPlay = false;
_playerKey = UniqueKey();
_isStopped = true;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _urlController,
decoration: const InputDecoration(
labelText: 'Stream URL',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
height: 300,
child: IvsVideoPlayer(
key: _playerKey,
url: _urlController.text,
showOverlayControls: _showOverlayControls,
controller: _controller,
autoPlay: _currentAutoPlay,
onError: (error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $error')),
);
},
),
),
const SizedBox(height: 16),
AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Column(
children: [
Text(
'State: ${_isStopped ? "stopped" : _controller.state}'),
if (_controller.hasError)
Text('Error: ${_controller.errorMessage}'),
const SizedBox(height: 16),
Wrap(
alignment: WrapAlignment.spaceEvenly,
spacing: 8.0,
children: [
ElevatedButton(
onPressed: () {
if (_controller.state == PlayerState.paused) {
_controller.resume();
} else {
_controller.play(_urlController.text);
}
setState(() {
_isStopped = false;
});
},
child: const Text('Play'),
),
ElevatedButton(
onPressed: _controller.state == PlayerState.playing
? () => _controller.pause()
: null,
child: const Text('Pause'),
),
ElevatedButton(
onPressed: _stopPlayer,
child: const Text('Stop'),
),
],
),
],
);
},
),
],
),
),
);
}
}