Skip to content

Commit aa65dd4

Browse files
authored
[video_player_videohole] Synchronize isPlaying state (#854)
1 parent 33938df commit aa65dd4

File tree

9 files changed

+47
-5
lines changed

9 files changed

+47
-5
lines changed

packages/video_player_videohole/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.4
2+
3+
* Synchronize isPlaying state.
4+
15
## 0.5.3
26

37
* Add 'isCompleted' event to 'VideoPlayerEvent'.

packages/video_player_videohole/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To use this package, add `video_player_videohole` as a dependency in your `pubsp
1212

1313
```yaml
1414
dependencies:
15-
video_player_videohole: ^0.5.3
15+
video_player_videohole: ^0.5.4
1616
```
1717
1818
Then you can import `video_player_videohole` in your Dart code:

packages/video_player_videohole/lib/src/video_player_tizen.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
236236
eventType: VideoEventType.subtitleUpdate,
237237
text: map['text']! as String,
238238
);
239+
case 'isPlayingStateUpdate':
240+
return VideoEvent(
241+
eventType: VideoEventType.isPlayingStateUpdate,
242+
isPlaying: map['isPlaying']! as bool,
243+
);
239244
default:
240245
return VideoEvent(eventType: VideoEventType.unknown);
241246
}

packages/video_player_videohole/lib/video_player.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
482482
text: event.text ?? '',
483483
);
484484
value = value.copyWith(caption: caption);
485+
case VideoEventType.isPlayingStateUpdate:
486+
if (event.isPlaying ?? false) {
487+
value = value.copyWith(
488+
isPlaying: event.isPlaying,
489+
isCompleted: false,
490+
);
491+
} else {
492+
value = value.copyWith(isPlaying: event.isPlaying);
493+
}
485494
case VideoEventType.unknown:
486495
break;
487496
}

packages/video_player_videohole/lib/video_player_platform_interface.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class VideoEvent {
268268
this.size,
269269
this.buffered,
270270
this.text,
271+
this.isPlaying,
271272
});
272273

273274
/// The type of the event.
@@ -293,6 +294,11 @@ class VideoEvent {
293294
/// Only used if [eventType] is [VideoEventType.subtitleUpdate].
294295
final String? text;
295296

297+
/// Whether the video is currently playing.
298+
///
299+
/// Only used if [eventType] is [VideoEventType.isPlayingStateUpdate].
300+
final bool? isPlaying;
301+
296302
@override
297303
bool operator ==(Object other) {
298304
return identical(this, other) ||
@@ -337,6 +343,12 @@ enum VideoEventType {
337343
/// Updated the video subtitle text.
338344
subtitleUpdate,
339345

346+
/// The playback state of the video has changed.
347+
///
348+
/// This event is fired when the video starts or pauses due to user actions or
349+
/// phone calls, or other app media such as music players.
350+
isPlayingStateUpdate,
351+
340352
/// An unknown event has been received.
341353
unknown,
342354
}

packages/video_player_videohole/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_videohole
22
description: Flutter plugin for displaying inline video on Tizen TV devices.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_videohole
5-
version: 0.5.3
5+
version: 0.5.4
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

packages/video_player_videohole/tizen/src/media_player.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ bool MediaPlayer::Play() {
214214
LOG_ERROR("[MediaPlayer] player_start failed: %s.", get_error_message(ret));
215215
return false;
216216
}
217+
SendIsPlayingState(true);
217218
return true;
218219
}
219220

@@ -238,6 +239,7 @@ bool MediaPlayer::Pause() {
238239
LOG_ERROR("[MediaPlayer] player_pause failed: %s.", get_error_message(ret));
239240
return false;
240241
}
242+
SendIsPlayingState(false);
241243
return true;
242244
}
243245

@@ -679,10 +681,9 @@ void MediaPlayer::OnPlayCompleted(void *user_data) {
679681

680682
void MediaPlayer::OnInterrupted(player_interrupted_code_e code,
681683
void *user_data) {
682-
LOG_ERROR("[MediaPlayer] Interrupt code: %d.", code);
683-
684684
MediaPlayer *self = static_cast<MediaPlayer *>(user_data);
685-
self->SendError("Interrupted error", "Media player has been interrupted.");
685+
self->SendIsPlayingState(false);
686+
LOG_ERROR("[MediaPlayer] Interrupt code: %d.", code);
686687
}
687688

688689
void MediaPlayer::OnError(int error_code, void *user_data) {

packages/video_player_videohole/tizen/src/video_player.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ void VideoPlayer::SendPlayCompleted() {
162162
PushEvent(flutter::EncodableValue(result));
163163
}
164164

165+
void VideoPlayer::SendIsPlayingState(bool is_playing) {
166+
flutter::EncodableMap result = {
167+
{flutter::EncodableValue("event"),
168+
flutter::EncodableValue("isPlayingStateUpdate")},
169+
{flutter::EncodableValue("isPlaying"),
170+
flutter::EncodableValue(is_playing)},
171+
};
172+
PushEvent(flutter::EncodableValue(result));
173+
}
174+
165175
void VideoPlayer::SendError(const std::string &error_code,
166176
const std::string &error_message) {
167177
if (event_sink_) {

packages/video_player_videohole/tizen/src/video_player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class VideoPlayer {
6161
void SendBufferingEnd();
6262
void SendSubtitleUpdate(int32_t duration, const std::string &text);
6363
void SendPlayCompleted();
64+
void SendIsPlayingState(bool is_playing);
6465
void SendError(const std::string &error_code,
6566
const std::string &error_message);
6667

0 commit comments

Comments
 (0)