From 7057f871e29e0e76e7136df9f07352dbf53f9152 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 21 Aug 2021 00:05:13 +0900 Subject: [PATCH] [video_player] improve asset path (#37) --- .../elinux/video_player_elinux_plugin.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/video_player/elinux/video_player_elinux_plugin.cc b/packages/video_player/elinux/video_player_elinux_plugin.cc index b43ffdb..60ee309 100644 --- a/packages/video_player/elinux/video_player_elinux_plugin.cc +++ b/packages/video_player/elinux/video_player_elinux_plugin.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -131,6 +132,8 @@ class VideoPlayerPlugin : public flutter::Plugin { const std::string& code = std::string(), const std::string& details = std::string()); + const std::string GetExecutableDirectory(); + flutter::PluginRegistrar* plugin_registrar_; flutter::TextureRegistrar* texture_registrar_; std::unordered_map> players_; @@ -283,7 +286,7 @@ void VideoPlayerPlugin::HandleCreateMethodCall( std::string uri; if (!meta.GetAsset().empty()) { // todo: gets propery path of the Flutter project. - std::string flutter_project_path = "./bundle/data/"; + std::string flutter_project_path = GetExecutableDirectory() + "/data/"; uri = flutter_project_path + "flutter_assets/" + meta.GetAsset(); } else { uri = meta.GetUri(); @@ -587,6 +590,15 @@ flutter::EncodableValue VideoPlayerPlugin::WrapError( return flutter::EncodableValue(map); } +const std::string VideoPlayerPlugin::GetExecutableDirectory() { + static char buf[1024] = {}; + readlink("/proc/self/exe", buf, sizeof(buf) - 1); + + std::string exe_path = std::string(buf); + const int slash_pos = exe_path.find_last_of('/'); + return exe_path.substr(0, slash_pos); +} + } // namespace void VideoPlayerElinuxPluginRegisterWithRegistrar(