-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevent_subscription.dart
136 lines (126 loc) · 4.09 KB
/
event_subscription.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:bitmovin_player/bitmovin_player.dart';
import 'package:bitmovin_player_example/controls.dart';
import 'package:bitmovin_player_example/env/env.dart';
import 'package:bitmovin_player_example/events.dart';
import 'package:bitmovin_player_example/platform.dart';
import 'package:bitmovin_player_example/player_info.dart';
import 'package:bitmovin_player_example/player_view_container.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
class EventSubscription extends StatefulWidget {
const EventSubscription({super.key});
static String routeName = 'EventSubscription';
@override
State<EventSubscription> createState() => _EventSubscriptionState();
}
class _EventSubscriptionState extends State<EventSubscription> {
final _eventsKey = GlobalKey<EventsState>();
final _playerInfoKey = GlobalKey<PlayerInfoState>();
final _sourceConfig = SourceConfig(
url: isIOS
? 'https://cdn.bitmovin.com/content/assets/MI201109210084/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8'
: 'https://cdn.bitmovin.com/content/assets/MI201109210084/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd',
type: isIOS ? SourceType.hls : SourceType.dash,
);
final _player = Player(
config: const PlayerConfig(
key: Env.bitmovinPlayerLicenseKey,
remoteControlConfig: RemoteControlConfig(isCastEnabled: false),
),
);
final _logger = Logger();
void _onEvent(Event event) {
_playerInfoKey.currentState?.updatePlayerInfo(_player, event);
final eventName = '${event.runtimeType}';
final eventData = '$eventName ${event.toJson()}';
_logger.d(eventData);
_eventsKey.currentState?.add(eventName);
}
void _listen() {
_player
..onError = _onEvent
..onInfo = _onEvent
..onSourceLoad = _onEvent
..onSourceLoaded = _onEvent
..onMuted = _onEvent
..onPaused = _onEvent
..onPlay = _onEvent
..onPlaybackFinished = _onEvent
..onPlaying = _onEvent
..onReady = _onEvent
..onSeek = _onEvent
..onSeeked = _onEvent
..onSourceAdded = _onEvent
..onSourceRemoved = _onEvent
..onSourceError = _onEvent
..onSourceInfo = _onEvent
..onSourceUnloaded = _onEvent
..onSourceWarning = _onEvent
..onTimeChanged = _onEvent
..onUnmuted = _onEvent
..onWarning = _onEvent
..onSubtitleAdded = _onEvent
..onSubtitleRemoved = _onEvent
..onSubtitleChanged = _onEvent
..onCueEnter = _onEvent
..onCueExit = _onEvent
..onAirPlayAvailable = _onEvent
..onAirPlayChanged = _onEvent;
}
@override
void initState() {
_listen();
_player.loadSourceConfig(_sourceConfig);
super.initState();
}
@override
void setState(VoidCallback fn) {
if (mounted) {
super.setState(fn);
}
}
@override
void dispose() {
_player.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Event Subscription'),
),
body: Column(
children: [
PlayerViewContainer(player: _player),
Container(
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
onUnmutePressed: _player.unmute,
onSkipForwardPressed: () async =>
_player.seek(await _player.currentTime + 10),
onSkipBackwardPressed: () async =>
_player.seek(await _player.currentTime - 10),
),
),
Expanded(
child: Container(
margin: const EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Events(key: _eventsKey),
),
),
Expanded(
child: Container(
margin: const EdgeInsets.fromLTRB(10, 10, 10, 10),
child: PlayerInfo(key: _playerInfoKey),
),
),
],
),
);
}
}