Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions example/lib/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Controls extends StatelessWidget {
required this.onPlayPressed,
required this.onPausePressed,
required this.onLoadPressed,
required this.onUnloadPressed,
required this.onMutePressed,
required this.onUnmutePressed,
required this.onSkipForwardPressed,
Expand All @@ -17,6 +18,7 @@ class Controls extends StatelessWidget {
final ControlAction onPlayPressed;
final ControlAction onPausePressed;
final ControlAction onLoadPressed;
final ControlAction onUnloadPressed;
final ControlAction onMutePressed;
final ControlAction onUnmutePressed;
final ControlAction onSkipForwardPressed;
Expand Down Expand Up @@ -66,10 +68,6 @@ class Controls extends StatelessWidget {
child: Wrap(
spacing: 8,
children: [
OutlinedButton(
onPressed: onLoadPressed,
child: const Text('Reload'),
),
OutlinedButton(
onPressed: onSkipBackwardPressed,
child: const Text('Skip Back'),
Expand All @@ -84,6 +82,29 @@ class Controls extends StatelessWidget {
),
],
),
Row(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Wrap(
spacing: 8,
children: [
OutlinedButton(
onPressed: onLoadPressed,
child: const Text('Reload'),
),
OutlinedButton(
onPressed: onUnloadPressed,
child: const Text('Unload'),
),
],
),
),
),
],
),
],
);
}
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class _PlayerAnalyticsState extends State<PlayerAnalytics> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/audio_only.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _AudioOnlyState extends State<AudioOnly> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/background_playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _BackgroundPlaybackState extends State<BackgroundPlayback> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/basic_playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _BasicPlaybackState extends State<BasicPlayback> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/casting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class _CastingState extends State<Casting> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => player.loadSourceConfig(_sourceConfig),
onUnloadPressed: player.unload,
onPlayPressed: player.play,
onPausePressed: player.pause,
onMutePressed: player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/custom_html_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class _CustomHtmlUiState extends State<CustomHtmlUi> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/drm_playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class _DrmPlaybackState extends State<DrmPlayback> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/event_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class _EventSubscriptionState extends State<EventSubscription> {
margin: const EdgeInsets.only(top: 5),
child: Controls(
onLoadPressed: () => _player.loadSourceConfig(_sourceConfig),
onUnloadPressed: _player.unload,
onPlayPressed: _player.play,
onPausePressed: _player.pause,
onMutePressed: _player.mute,
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/Event+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ extension SourceRemovedEvent {

extension SourceLoadEvent: SourceEventType {}
extension SourceLoadedEvent: SourceEventType {}
extension SourceUnloadEvent: SourceEventType {}
extension SourceUnloadedEvent: SourceEventType {}

internal protocol TimedEventType: Event {
Expand Down
4 changes: 3 additions & 1 deletion ios/Classes/FlutterPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private extension FlutterPlayer {
} else {
throw BitmovinError.parsingError("Could not parse arguments for \(call.method)")
}
case (Methods.unload, .empty):
player.unload()
case (Methods.play, .empty):
player.play()
case (Methods.pause, .empty):
Expand Down Expand Up @@ -244,7 +246,7 @@ extension FlutterPlayer: PlayerListener {
}

func onSourceUnload(_ event: SourceUnloadEvent, player: Player) {
broadcast(name: event.name, data: event.toJsonFallback(), sink: eventSink)
broadcast(name: event.name, data: event.toJSON(), sink: eventSink)
}

func onSourceWarning(_ event: SourceWarningEvent, player: Player) {
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/Methods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal enum Methods {
static let createPlayer = "createPlayer"
static let loadWithSourceConfig = "loadWithSourceConfig"
static let loadWithSource = "loadWithSource"
static let unload = "unload"
static let play = "play"
static let pause = "pause"
static let mute = "mute"
Expand Down
4 changes: 4 additions & 0 deletions lib/src/api/player/player_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ abstract class PlayerApi {
/// the provided [SourceConfig].
Future<void> loadSourceConfig(SourceConfig sourceConfig);

/// Unloads the currently loaded source from the player.
/// If no source is loaded, this is a no-op.
Future<void> unload();

/// Starts or resumes playback.
Future<void> play();

Expand Down
1 change: 1 addition & 0 deletions lib/src/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Methods {
static const String createPlayer = 'createPlayer';
static const String loadWithSourceConfig = 'loadWithSourceConfig';
static const String loadWithSource = 'loadWithSource';
static const String unload = 'unload';
static const String play = 'play';
static const String pause = 'pause';
static const String mute = 'mute';
Expand Down
6 changes: 6 additions & 0 deletions lib/src/platform/player_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ abstract class PlayerPlatformInterface extends PlatformInterface
widevineHandler = WidevineHandler(widevineConfig);
}
}

@override
Future<void> unload() async {
fairplayHandler = null;
widevineHandler = null;
}
}

class _AnalyticsApi implements AnalyticsApi {
Expand Down
6 changes: 6 additions & 0 deletions lib/src/platform/player_platform_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ class PlayerPlatformMethodChannel extends PlayerPlatformInterface {
return _invokeMethod<void>(Methods.loadWithSource, source.toJson());
}

@override
Future<void> unload() async {
await super.unload();
return _invokeMethod<void>(Methods.unload);
}

@override
Future<double> get maxTimeShift async =>
_invokeMethod<double>(Methods.maxTimeShift);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Player with PlayerEventHandler implements PlayerApi {
Future<void> loadSource(Source source) async =>
_playerPlatformInterface.loadSource(source);

@override
Future<void> unload() async => _playerPlatformInterface.unload();

@override
Future<void> play() async => _playerPlatformInterface.play();

Expand Down