-
Notifications
You must be signed in to change notification settings - Fork 284
Enhancements: Start Time Initialization and Extended Volume Range #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
769fa43
de94ba2
36b2b8a
f59d0cd
c0c3e60
03e8d54
480eddd
bc37187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,8 @@ import 'package:flutter_vlc_player_platform_interface/flutter_vlc_player_platfor | |
| /// | ||
| /// After [dispose] all further calls are ignored. | ||
| class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | ||
| static const _maxVolume = 100; | ||
| int _maxVolume = 100; | ||
| bool _startAtSet = false; | ||
|
|
||
| /// The URI to the video file. This will be in different formats depending on | ||
| /// the [DataSourceType] of the original video. | ||
|
|
@@ -39,6 +40,9 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| /// Initialize vlc player when the platform is ready automatically | ||
| final bool autoInitialize; | ||
|
|
||
| /// Video start from [startAt]. When initialization is complete | ||
| final Duration? startAt; | ||
|
|
||
| /// Set keep playing video in background, when app goes in background. | ||
| /// The default value is false. | ||
| final bool allowBackgroundPlayback; | ||
|
|
@@ -71,7 +75,6 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
|
|
||
| /// List of onRenderer listeners | ||
| final List<RendererCallback> _onRendererEventListeners = []; | ||
|
|
||
| bool _isDisposed = false; | ||
|
|
||
| VlcAppLifeCycleObserver? _lifeCycleObserver; | ||
|
|
@@ -96,6 +99,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| this.dataSource, { | ||
| this.autoInitialize = true, | ||
| this.allowBackgroundPlayback = false, | ||
| this.startAt, | ||
| this.package, | ||
| this.hwAcc = HwAcc.auto, | ||
| this.autoPlay = true, | ||
|
|
@@ -118,6 +122,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| this.dataSource, { | ||
| this.autoInitialize = true, | ||
| this.allowBackgroundPlayback = false, | ||
| this.startAt, | ||
| this.hwAcc = HwAcc.auto, | ||
| this.autoPlay = true, | ||
| this.options, | ||
|
|
@@ -139,6 +144,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| File file, { | ||
| this.autoInitialize = true, | ||
| this.allowBackgroundPlayback = true, | ||
| this.startAt, | ||
| this.hwAcc = HwAcc.auto, | ||
| this.autoPlay = true, | ||
| this.options, | ||
|
|
@@ -233,6 +239,10 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| ); | ||
| break; | ||
| case VlcMediaEventType.playing: | ||
|
|
||
| /// Calling start at | ||
| if (startAt != null && !_startAtSet) _setStartAt(); | ||
|
|
||
| value = value.copyWith( | ||
| isEnded: false, | ||
| isPlaying: true, | ||
|
|
@@ -349,6 +359,26 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| return initializingCompleter.future; | ||
| } | ||
|
|
||
| /// Seeking to start at | ||
| Future<void> _setStartAt() async { | ||
| // Check if already seted up or start at is null then return. | ||
| if (startAt == null || _startAtSet) return; | ||
|
|
||
| final Duration startAtDuration = startAt ?? Duration.zero; | ||
|
|
||
| // Checking if startAt is greatet then video's duration then throw error. | ||
| if (startAtDuration.inMilliseconds > value.duration.inMilliseconds) { | ||
| throw ArgumentError.value( | ||
| startAtDuration, | ||
| 'Start At cannot be greater than video duration.', | ||
| ); | ||
|
||
| } | ||
|
|
||
| // Setting startAt | ||
| _startAtSet = true; | ||
| await seekTo(startAtDuration); | ||
| } | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Dispose controller | ||
| @override | ||
| Future<void> dispose() async { | ||
|
|
@@ -394,6 +424,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| String? package, | ||
| bool? autoPlay, | ||
| HwAcc? hwAcc, | ||
| Duration? startAt, | ||
| }) async { | ||
| _dataSourceType = DataSourceType.asset; | ||
| this.package = package; | ||
|
|
@@ -403,6 +434,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| package: package, | ||
| autoPlay: autoPlay, | ||
| hwAcc: hwAcc, | ||
| startAt: startAt, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -414,6 +446,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| String dataSource, { | ||
| bool? autoPlay, | ||
| HwAcc? hwAcc, | ||
| Duration? startAt, | ||
| }) async { | ||
| _dataSourceType = DataSourceType.network; | ||
| package = null; | ||
|
|
@@ -422,6 +455,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| dataSourceType: DataSourceType.network, | ||
| autoPlay: autoPlay, | ||
| hwAcc: hwAcc, | ||
| startAt: startAt, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -433,6 +467,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| File file, { | ||
| bool? autoPlay, | ||
| HwAcc? hwAcc, | ||
| Duration? startAt, | ||
| }) async { | ||
| _dataSourceType = DataSourceType.file; | ||
| package = null; | ||
|
|
@@ -442,6 +477,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| dataSourceType: DataSourceType.file, | ||
| autoPlay: autoPlay, | ||
| hwAcc: hwAcc, | ||
| startAt: startAt, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -456,6 +492,7 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| String? package, | ||
| bool? autoPlay, | ||
| HwAcc? hwAcc, | ||
| Duration? startAt, | ||
| }) async { | ||
| _throwIfNotInitialized('setStreamUrl'); | ||
| await vlcPlayerPlatform.stop(_viewId); | ||
|
|
@@ -468,6 +505,10 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| autoPlay: autoPlay ?? true, | ||
| ); | ||
|
|
||
| if (startAt != null) { | ||
| await vlcPlayerPlatform.seekTo(_viewId, startAt); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -557,9 +598,38 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> { | |
| return position; | ||
| } | ||
|
|
||
| /// Sets the max audio volume of | ||
| /// | ||
| /// [maxVolume] indicates a value between 1 (lowest) and 200 (highest) on a | ||
| /// linear scale. | ||
| Future<void> setMaxVolume(int maxVolume) async { | ||
| _throwIfNotInitialized('setMaxVolume'); | ||
| if (maxVolume > 200) { | ||
| throw ArgumentError.value( | ||
| maxVolume, | ||
| 'Max volume should be lower than 200.', | ||
itsSagarBro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } else if (maxVolume <= 0) { | ||
| throw ArgumentError.value( | ||
| maxVolume, | ||
| 'Max volume should not be 0 or negative.', | ||
| ); | ||
| } | ||
| _maxVolume = maxVolume; | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| /// Returns current vlc max volume level. | ||
| Future<int> getMaxVolume() async { | ||
| _throwIfNotInitialized('getMaxVolume'); | ||
|
|
||
| return _maxVolume; | ||
| } | ||
|
|
||
| /// Sets the audio volume of | ||
| /// | ||
| /// [volume] indicates a value between 0 (silent) and 100 (full volume) on a | ||
| /// [volume] indicates a value between 0 (silent), 100 (full volume) and 200 (maximum) on a | ||
| /// linear scale. | ||
| Future<void> setVolume(int volume) async { | ||
| _throwIfNotInitialized('setVolume'); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.