[video_player] improve asset path (#37)

This commit is contained in:
Hidenori Matsubayashi
2021-08-21 00:05:13 +09:00
committed by GitHub
parent fe274a8038
commit 7057f871e2
@@ -12,6 +12,7 @@
#include <flutter/plugin_registrar.h>
#include <flutter/standard_message_codec.h>
#include <flutter/standard_method_codec.h>
#include <unistd.h>
#include <unordered_map>
@@ -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<int64_t, std::unique_ptr<FlutterVideoPlayer>> 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(