@@ -134,7 +134,8 @@ int64_t PlusPlayer::Create(const std::string &uri,
134134 create_message.player_options (), " startPosition" , (int64_t )0 );
135135 if (start_position > 0 ) {
136136 LOG_INFO (" [PlusPlayer] Start position: %lld" , start_position);
137- if (!plusplayer_seek (player_, start_position)) {
137+ if (plusplayer_seek (player_, start_position) !=
138+ PLUSPLAYER_ERROR_TYPE_NONE) {
138139 LOG_INFO (" [PlusPlayer] Fail to seek, it's a non-seekable content" );
139140 }
140141 }
@@ -768,10 +769,7 @@ void PlusPlayer::SetStreamingProperty(const std::string &type,
768769
769770 LOG_INFO (" [PlusPlayer] SetStreamingProp: type[%s], value[%s]" , type.c_str (),
770771 value.c_str ());
771- if (value == " true" ) {
772- LOG_INFO (" [PlusPlayer] Streaming property value is true" );
773- // TODO: handle true case if needed
774- }
772+ plusplayer_set_property (player_, ConvertPropertyType (type), value.c_str ());
775773}
776774
777775bool PlusPlayer::SetDisplayRotate (int64_t rotation) {
@@ -1019,87 +1017,27 @@ bool PlusPlayer::RestorePlayer(const CreateMessage *restore_message,
10191017 return true ;
10201018}
10211019
1022- std::string BuildJsonString (const flutter::EncodableMap &data) {
1023- rapidjson::Document doc;
1024- doc.SetObject ();
1025- rapidjson::Document::AllocatorType &allocator = doc.GetAllocator ();
1026-
1027- for (const auto &pair : data) {
1028- std::string key_str = std::get<std::string>(pair.first );
1029- rapidjson::Value key (key_str.c_str (), allocator);
1030- if (key_str == " max-bandwidth" ) {
1031- doc.AddMember (key, rapidjson::Value (std::get<int64_t >(pair.second )),
1032- allocator);
1033- } else {
1034- doc.AddMember (key,
1035- rapidjson::Value (std::get<std::string>(pair.second ).c_str (),
1036- allocator),
1037- allocator);
1038- }
1039- }
1040- rapidjson::StringBuffer buffer;
1041- rapidjson::Writer<rapidjson::StringBuffer> writer (buffer);
1042- doc.Accept (writer);
1043- return buffer.GetString ();
1044- }
1045-
1046- std::string BuildJsonString (const flutter::EncodableList &encodable_keys) {
1047- rapidjson::Document doc;
1048- doc.SetObject ();
1049- rapidjson::Document::AllocatorType &allocator = doc.GetAllocator ();
1050-
1051- for (const auto &encodable_key : encodable_keys) {
1052- std::string key_str = std::get<std::string>(encodable_key);
1053- rapidjson::Value key (key_str.c_str (), allocator);
1054- if (key_str == " max-bandwidth" ) {
1055- doc.AddMember (key, 0 , allocator);
1056- } else {
1057- doc.AddMember (key, " " , allocator);
1058- }
1059- }
1060- rapidjson::StringBuffer buffer;
1061- rapidjson::Writer<rapidjson::StringBuffer> writer (buffer);
1062- doc.Accept (writer);
1063- return buffer.GetString ();
1064- }
1065-
1066- void ParseJsonString (std::string json_str,
1067- const flutter::EncodableList &encodable_keys,
1068- flutter::EncodableMap &output) {
1069- rapidjson::Document doc;
1070- doc.Parse (json_str.c_str ());
1071- if (doc.HasParseError ()) {
1072- LOG_ERROR (" [PlusPlayer] Fail to parse json string." );
1073- return ;
1074- }
1075- for (const auto &encodable_key : encodable_keys) {
1076- std::string key_str = std::get<std::string>(encodable_key);
1077- if (doc.HasMember (key_str.c_str ())) {
1078- if (key_str == " max-bandwidth" ) {
1079- output.insert_or_assign (
1080- encodable_key,
1081- flutter::EncodableValue (doc[key_str.c_str ()].GetInt64 ()));
1082- } else {
1083- output.insert_or_assign (
1084- encodable_key,
1085- flutter::EncodableValue (doc[key_str.c_str ()].GetString ()));
1086- }
1087- }
1088- }
1089- }
1090-
10911020bool PlusPlayer::SetData (const flutter::EncodableMap &data) {
10921021 if (!player_) {
10931022 LOG_ERROR (" [PlusPlayer] Player not created." );
10941023 return false ;
10951024 }
1096- std::string json_data = BuildJsonString (data);
1097- if (json_data.empty ()) {
1098- LOG_ERROR (" [PlusPlayer] json_data is empty." );
1099- return false ;
1025+ bool result = true ;
1026+ for (const auto &pair : data) {
1027+ std::string key = std::get<std::string>(pair.first );
1028+ std::string value;
1029+ if (key == " max-bandwidth" ) {
1030+ value = std::to_string (std::get<int64_t >(pair.second ));
1031+ } else {
1032+ value = std::get<std::string>(pair.second );
1033+ }
1034+ if (plusplayer_set_property (player_, ConvertPropertyType (key),
1035+ value.c_str ()) != PLUSPLAYER_ERROR_TYPE_NONE) {
1036+ LOG_ERROR (" [PlusPlayer] Fail to set property, key : %s" , key.c_str ());
1037+ result = false ;
1038+ }
11001039 }
1101- return false ;
1102- // return ::SetData(player_, json_data);
1040+ return result;
11031041}
11041042
11051043flutter::EncodableMap PlusPlayer::GetData (const flutter::EncodableList &data) {
@@ -1108,19 +1046,24 @@ flutter::EncodableMap PlusPlayer::GetData(const flutter::EncodableList &data) {
11081046 LOG_ERROR (" [PlusPlayer] Player not created." );
11091047 return result;
11101048 }
1111- std::string json_data = BuildJsonString (data);
1112- if (json_data.empty ()) {
1113- LOG_ERROR (" [PlusPlayer] json_data is empty." );
1114- return result;
1115- }
1116- return {};
1117- /*
1118- if (!::GetData(player_, json_data)) {
1119- LOG_ERROR("[PlusPlayer] Fail to get data from player");
1120- return result;
1049+
1050+ for (const auto &encodable_key : data) {
1051+ std::string key = std::get<std::string>(encodable_key);
1052+ char *value;
1053+ if (plusplayer_get_property (player_, ConvertPropertyType (key), &value) !=
1054+ PLUSPLAYER_ERROR_TYPE_NONE) {
1055+ LOG_ERROR (" [PlusPlayer] Fail to get property, key : %s" , key.c_str ());
1056+ continue ;
11211057 }
1122- */
1123- ParseJsonString (json_data, data, result);
1058+ if (key == " max-bandwidth" ) {
1059+ result.insert_or_assign (encodable_key,
1060+ flutter::EncodableValue (std::stoll (value)));
1061+ } else {
1062+ result.insert_or_assign (encodable_key,
1063+ flutter::EncodableValue (std::string (value)));
1064+ }
1065+ free (value);
1066+ }
11241067 return result;
11251068}
11261069
0 commit comments