Skip to content

Commit

Permalink
initialized event after texture size is available. #145
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Aug 29, 2024
1 parent 9fd8ea7 commit 3360204
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Player {
return _texId;
}

Future<ui.Size?> get textureSize => _videoSize.future;

/// Mute the audio or not
set mute(bool value) {
_mute = value;
Expand Down
29 changes: 12 additions & 17 deletions lib/src/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,19 @@ class MdkVideoPlayer extends mdk.Player {
return true;
}
_initialized = true;
final info = mediaInfo;
var size = const Size(0, 0);
if (info.video != null) {
final vc = info.video![0].codec;
size = Size(vc.width.toDouble(),
(vc.height.toDouble() / vc.par).roundToDouble());
if (info.video![0].rotation % 180 == 90) {
size = Size(size.height, size.width);
textureSize.then((size) {
if (size == null) {
return;
}
}
streamCtl.add(VideoEvent(
eventType: VideoEventType.initialized,
duration: Duration(
microseconds: isLive
streamCtl.add(VideoEvent(
eventType: VideoEventType.initialized,
duration: Duration(
microseconds: isLive
// int max for live streams, duration.inMicroseconds == 9223372036854775807
? double.maxFinite.toInt()
: info.duration * 1000),
size: size));
? double.maxFinite.toInt()
: mediaInfo.duration * 1000),
size: size));
});
} else if (!oldValue.test(mdk.MediaStatus.buffering) &&
newValue.test(mdk.MediaStatus.buffering)) {
streamCtl.add(VideoEvent(eventType: VideoEventType.bufferingStart));
Expand Down Expand Up @@ -281,7 +276,7 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
_players[-hashCode] = player;
player.streamCtl.addError(PlatformException(
code: 'video size error',
message: 'invalid or unsupported media',
message: 'invalid or unsupported media with invalid video size',
));
//player.dispose();
return -hashCode;
Expand Down

0 comments on commit 3360204

Please sign in to comment.