@@ -57,7 +57,7 @@ class VideoPlayerService {
5757 /// Returns `false` if the video has not been initialized.
5858 bool get isPlaying {
5959 try {
60- return _controller! .value.isPlaying;
60+ return _controller? .value.isPlaying ?? false ;
6161 } catch (error, stackTrace) {
6262 log (
6363 'Could not get playing status!' ,
@@ -74,7 +74,7 @@ class VideoPlayerService {
7474 /// Returns [Duration.zero] if the video has not been initialized.
7575 Duration get position {
7676 try {
77- return _controller! .value.position;
77+ return _controller? .value.position ?? Duration .zero ;
7878 } catch (error, stackTrace) {
7979 log (
8080 'Could not get position!' ,
@@ -91,7 +91,7 @@ class VideoPlayerService {
9191 /// Returns [Duration.zero] if the video has not been initialized.
9292 Duration get duration {
9393 try {
94- return _controller! .value.duration;
94+ return _controller? .value.duration ?? Duration .zero ;
9595 } catch (error, stackTrace) {
9696 log (
9797 'Could not get duration!' ,
@@ -108,7 +108,7 @@ class VideoPlayerService {
108108 /// Returns `1` if the video has not been initialized.
109109 double get playbackSpeed {
110110 try {
111- return _controller! .value.playbackSpeed;
111+ return _controller? .value.playbackSpeed ?? 1 ;
112112 } catch (error, stackTrace) {
113113 log (
114114 'Could not get playback speed!' ,
@@ -125,7 +125,7 @@ class VideoPlayerService {
125125 /// Returns `0` if the video has not been initialized.
126126 double get height {
127127 try {
128- return _controller! .value.size.height;
128+ return _controller? .value.size.height ?? 0 ;
129129 } catch (error, stackTrace) {
130130 log (
131131 'Could not get height!' ,
@@ -142,7 +142,7 @@ class VideoPlayerService {
142142 /// Returns `0` if the video has not been initialized.
143143 double get width {
144144 try {
145- return _controller! .value.size.width;
145+ return _controller? .value.size.width ?? 0 ;
146146 } catch (error, stackTrace) {
147147 log (
148148 'Could not get width!' ,
@@ -166,8 +166,8 @@ class VideoPlayerService {
166166 );
167167 }
168168
169- await _controller! .initialize ();
170- await _controller! .setVolume (volume);
169+ await _controller? .initialize ();
170+ await _controller? .setVolume (volume);
171171 } catch (error, stackTrace) {
172172 log (
173173 'Could not load file!' ,
@@ -198,7 +198,7 @@ class VideoPlayerService {
198198 /// Throws a [PlayVideoException] if the video fails to play.
199199 Future <void > play () async {
200200 try {
201- await _controller! .play ();
201+ await _controller? .play ();
202202 } catch (error, stackTrace) {
203203 log (
204204 'Could not play the video!' ,
@@ -215,7 +215,7 @@ class VideoPlayerService {
215215 /// Throws a [PauseVideoException] if the video fails to pause.
216216 Future <void > pause () async {
217217 try {
218- await _controller! .pause ();
218+ await _controller? .pause ();
219219 } catch (error, stackTrace) {
220220 log (
221221 'Could not pause the video!' ,
@@ -232,7 +232,7 @@ class VideoPlayerService {
232232 /// Throws a [SetVideoPlaybackSpeedException] if could not set playback speed.
233233 Future <void > setPlaybackSpeed (double speed) async {
234234 try {
235- await _controller! .setPlaybackSpeed (speed);
235+ await _controller? .setPlaybackSpeed (speed);
236236 } catch (error, stackTrace) {
237237 log (
238238 'Could not set playback speed!' ,
@@ -249,7 +249,7 @@ class VideoPlayerService {
249249 /// Throws a [SetVolumeException] if the video fails to set the volume.
250250 Future <void > setVolume (double volume) async {
251251 try {
252- await _controller! .setVolume (volume);
252+ await _controller? .setVolume (volume);
253253 } catch (error, stackTrace) {
254254 log (
255255 'Could not set volume!' ,
@@ -266,7 +266,7 @@ class VideoPlayerService {
266266 /// Throws a [SeekVideoPositionException] if the video fails to seek.
267267 Future <void > seekTo (Duration position) async {
268268 try {
269- await _controller! .seekTo (position);
269+ await _controller? .seekTo (position);
270270 } catch (error, stackTrace) {
271271 log (
272272 'Could not seek to the position!' ,
@@ -281,7 +281,7 @@ class VideoPlayerService {
281281 /// Adds a listener to the video player.
282282 void addListener (VoidCallback listener) {
283283 try {
284- _controller! .addListener (listener);
284+ _controller? .addListener (listener);
285285 } catch (error, stackTrace) {
286286 log (
287287 'Could not add listener!' ,
0 commit comments