Skip to content

Commit

Permalink
Wrapper: Add Player::Error (alexmercerind#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Nov 8, 2021
1 parent d56e243 commit 9b95e98
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dartvlc/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void PlayerCreate(int32_t id, int32_t video_width, int32_t video_height,
[=](int32_t video_width, int32_t video_height) -> void {
OnVideoDimensions(id, video_width, video_height);
});
player->onError(
[=](std::string error) -> void { OnError(id, error.c_str()); });
}

void PlayerDispose(int32_t id) { g_players->Dispose(id); }
Expand Down
22 changes: 22 additions & 0 deletions dartvlc/api/eventmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ inline void OnBuffering(int32_t id, float buffering) {
g_dart_post_C_object(g_callback_port, &return_object);
}

inline void OnError(int32_t id, const char* error) {
Dart_CObject id_object;
id_object.type = Dart_CObject_kInt32;
id_object.value.as_int32 = id;

Dart_CObject type_object;
type_object.type = Dart_CObject_kString;
type_object.value.as_string = const_cast<char*>("errorEvent");

Dart_CObject error_object;
error_object.type = Dart_CObject_kString;
error_object.value.as_string = const_cast<char*>(error);

Dart_CObject* value_objects[] = {&id_object, &type_object, &error_object};

Dart_CObject return_object;
return_object.type = Dart_CObject_kArray;
return_object.value.as_array.length = 3;
return_object.value.as_array.values = value_objects;
g_dart_post_C_object(g_callback_port, &return_object);
}

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions dartvlc/internal/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ class PlayerEvents : public PlayerGetters {

void OnVideo(VideoFrameCallback callback) { video_callback_ = callback; }

void onError(std::function<void(std::string)> callback) {
vlc_media_player_.eventManager().onEncounteredError([=]() -> void {
auto error = libvlc_errmsg();
callback(error != NULL ? error : "");
});
}

protected:
std::function<void()> playlist_callback_ = [=]() -> void {};

Expand Down

0 comments on commit 9b95e98

Please sign in to comment.