Skip to content

Commit

Permalink
rename State to PlaybackState
Browse files Browse the repository at this point in the history
State conflicts with Widget State
  • Loading branch information
wang-bin committed Aug 11, 2023
1 parent 556a63e commit 1db20da
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.0

* fix fail to convert metadata to dart string
* rename `State` to `PlaybackState`

## 0.0.9

* add textureId notifier for Player
Expand Down
12 changes: 6 additions & 6 deletions lib/src/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MediaStatus {
}
}

enum State {
enum PlaybackState {
notRunning(MDK_State.MDK_State_NotRunning),
stopped(MDK_State.MDK_State_Stopped),
running(MDK_State.MDK_State_Running),
Expand All @@ -80,13 +80,13 @@ enum State {
;

final int rawValue;
const State(this.rawValue);
const PlaybackState(this.rawValue);

factory State.from(int i) {
factory PlaybackState.from(int i) {
const states = [
State.stopped,
State.playing,
State.paused,
PlaybackState.stopped,
PlaybackState.playing,
PlaybackState.paused,
];
return states[i];
}
Expand Down
24 changes: 12 additions & 12 deletions lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Player {
final oldValue = message[1] as int;
final newValue = message[2] as int;
if (_stateCb != null) {
_stateCb!(State.from(oldValue), State.from(newValue));
_stateCb!(PlaybackState.from(oldValue), PlaybackState.from(newValue));
}
Libfvp.replyType(nativeHandle, type, nullptr);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ class Player {
}
// await: ensure no player ref in fvp plugin before mdkPlayerAPI_delete() in dart
await updateTexture(width: -1);
state = State.stopped;
state = PlaybackState.stopped;
Libfvp.unregisterPort(nativeHandle);
onEvent(null);
onStateChanged(null);
Expand Down Expand Up @@ -193,16 +193,16 @@ class Player {

/// Set playback state to start, pause and stop the media.
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setstateplaybackstate-value
set state(State value) {
set state(PlaybackState value) {
_state = value;
_player.ref.setState.asFunction<void Function(Pointer<mdkPlayer>, int)>()(_player.ref.object, value.rawValue);
if (_state == State.stopped) {
if (_state == PlaybackState.stopped) {
_videoSize = Completer<ui.Size?>();
}
}

/// Current playback state.
State get state => _state;
PlaybackState get state => _state;

/// Current [MediaStatus] value
MediaStatus get mediaStatus => MediaStatus(_player.ref.mediaStatus.asFunction<int Function(Pointer<mdkPlayer>)>()(_player.ref.object));
Expand Down Expand Up @@ -243,8 +243,8 @@ class Player {
return MediaInfo.from(_mediaInfoC);
}

/// Load the [media] from [position] in milliseconds and decode the first frame, then [state] will be [State.paused].
/// If error occurs, will be [State.stopped].
/// Load the [media] from [position] in milliseconds and decode the first frame, then [state] will be [PlaybackState.paused].
/// If error occurs, will be [PlaybackState.stopped].
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-prepareint64_t-startposition--0-functionboolint64_t-position-bool-boost-cb--nullptr-seekflag-flags--seekflagfromstart
void prepare({int position = 0, SeekFlag flags = const SeekFlag(SeekFlag.defaultFlags)}) {
final cb = calloc<mdkPrepareCallback>();
Expand Down Expand Up @@ -306,7 +306,7 @@ class Player {
}

/// Wait for [state] in current thread
bool waitFor(State state, {int timeout = -1}) => _player.ref.waitFor.asFunction<bool Function(Pointer<mdkPlayer>, int, int)>()(_player.ref.object, state.rawValue, timeout);
bool waitFor(PlaybackState state, {int timeout = -1}) => _player.ref.waitFor.asFunction<bool Function(Pointer<mdkPlayer>, int, int)>()(_player.ref.object, state.rawValue, timeout);

/// Seek to [position] in milliseconds
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#bool-seekint64_t-pos-seekflag-flags-stdfunctionvoidint64_t-ret-cb--nullptr
Expand Down Expand Up @@ -447,10 +447,10 @@ class Player {
}
}

/// Set a [State] change callback.
/// Set a [PlaybackState] change callback.
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#player-onstatechangedstdfunctionvoidstate-cb
// reply: true to let native code wait for dart callback result
void onStateChanged(void Function(State oldValue, State newValue)? callback, {bool reply = false}) {
void onStateChanged(void Function(PlaybackState oldValue, PlaybackState newValue)? callback, {bool reply = false}) {
_stateCb = callback;
if (callback == null) {
Libfvp.unregisterType(nativeHandle, 1);
Expand Down Expand Up @@ -487,7 +487,7 @@ class Player {
final _receivePort = ReceivePort();

void Function(MediaEvent)? _eventCb;
void Function(State oldValue, State newValue)? _stateCb;
void Function(PlaybackState oldValue, PlaybackState newValue)? _stateCb;
final _statusCb = <bool Function(MediaStatus oldValue, MediaStatus newValue)>[];

bool _mute = false;
Expand All @@ -498,7 +498,7 @@ class Player {
List<int> _activeAT = [0];
List<int> _activeVT = [0];
List<int> _activeST = [0];
State _state = State.stopped;
PlaybackState _state = PlaybackState.stopped;
int _loop = 0;
bool _preloadImmediately = true;
double _playbackRate = 1.0;
Expand Down
8 changes: 4 additions & 4 deletions lib/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ class MdkVideoPlayer extends VideoPlayerPlatform {
Future<void> play(int textureId) async {
final player = _players[textureId];
if (player != null) {
player.state = mdk.State.playing;
player.state = mdk.PlaybackState.playing;
}
}

@override
Future<void> pause(int textureId) async {
final player = _players[textureId];
if (player != null) {
player.state = mdk.State.paused;
player.state = mdk.PlaybackState.paused;
}
}

Expand Down Expand Up @@ -238,9 +238,9 @@ class MdkVideoPlayer extends VideoPlayerPlatform {
});

player.onStateChanged((oldValue, newValue) {
_log.fine('$hashCode player${player.nativeHandle} onStateChanged: $oldValue => $newValue');
_log.fine('$hashCode player${player.nativeHandle} onPlaybackStateChanged: $oldValue => $newValue');
sc.add(VideoEvent(eventType: VideoEventType.isPlayingStateUpdate
, isPlaying: newValue == mdk.State.playing));
, isPlaying: newValue == mdk.PlaybackState.playing));
});
return sc;
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fvp
description: A plugin for video_player and APIs for your own players. Support all desktop/mobile platforms. Hardware decoders, optimal renders. Supports most formats via FFmpeg
version: 0.0.9
version: 0.1.0
homepage: https://github.com/wang-bin/fvp

environment:
Expand All @@ -14,7 +14,7 @@ dependencies:
logging: ^1.2.0
path: ^1.8.3
plugin_platform_interface: ^2.0.2
video_player_platform_interface: ^6.1.0
video_player_platform_interface: ^6.2.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 1db20da

Please sign in to comment.