@@ -447,6 +447,7 @@ void Quick2ViewCmdExecutor::GetAttribute(const ElementId& element, const std::st
447447 return ;
448448
449449 QVariant propertyValue = pItem->property (key.c_str ());
450+
450451 Value* val = NULL ;
451452
452453 if (propertyValue.isValid ()) {
@@ -815,6 +816,180 @@ void Quick2ViewCmdExecutor::ExecuteScript(const std::string& script, const base:
815816 *value = static_cast <Value*>(ret_value.release ());
816817}
817818
819+ void Quick2ViewCmdExecutor::GetPlayerState (const ElementId &element, PlayerState *state, Error **error)
820+ {
821+ QQuickView* view = getView (view_id_, error);
822+ if (NULL == view)
823+ return ;
824+
825+ QQuickItem* pItem = getElement (element, error);
826+ if (NULL == pItem)
827+ return ;
828+
829+
830+ base::Value* playbackState = NULL ;
831+ GetAttribute (element, " playbackState" , &playbackState, error);
832+
833+ if ( error != NULL && *error != NULL && (*error)->code () != kSuccess ){
834+ return ;
835+ }
836+
837+ int playbackStateInt;
838+ playbackState->GetAsInteger (&playbackStateInt);
839+
840+ *state = (PlayerState)playbackStateInt;
841+ }
842+
843+ void Quick2ViewCmdExecutor::SetPlayerState (const ElementId &element, PlayerState state, Error **error)
844+ {
845+ QQuickView* view = getView (view_id_, error);
846+ if (NULL == view)
847+ return ;
848+
849+ QQuickItem* pItem = getElement (element, error);
850+ if (NULL == pItem)
851+ return ;
852+
853+
854+ bool isMethodCalled = false ;
855+ switch (state){
856+ case Stopped: isMethodCalled = QMetaObject::invokeMethod (pItem, " stop" ); break ;
857+ case Playing: isMethodCalled = QMetaObject::invokeMethod (pItem, " play" ); break ;
858+ case Paused: isMethodCalled = QMetaObject::invokeMethod (pItem, " pause" ); break ;
859+ }
860+
861+ if (!isMethodCalled){
862+ (*error) = new Error (kUnknownError ,
863+ std::string (" Error while executing comand: There is no such member or the parameters did not match" ));
864+ }
865+ }
866+
867+ void Quick2ViewCmdExecutor::GetPlayerVolume (const ElementId &element, double *volume, Error **error)
868+ {
869+ QQuickView* view = getView (view_id_, error);
870+ if (NULL == view)
871+ return ;
872+
873+ QQuickItem* pItem = getElement (element, error);
874+ if (NULL == pItem)
875+ return ;
876+
877+
878+ base::Value* volumeValue = NULL ;
879+ GetAttribute (element, " volume" , &volumeValue, error);
880+
881+ if ( error != NULL && *error != NULL && (*error)->code () != kSuccess ){
882+ return ;
883+ }
884+
885+ int volumeInt;
886+ volumeValue->GetAsInteger (&volumeInt);
887+
888+ *volume = volumeInt/100.0 ;
889+ }
890+
891+ void Quick2ViewCmdExecutor::SetPlayerVolume (const ElementId &element, double volume, Error **error)
892+ {
893+ QQuickView* view = getView (view_id_, error);
894+ if (NULL == view)
895+ return ;
896+
897+ QQuickItem* pItem = getElement (element, error);
898+ if (NULL == pItem)
899+ return ;
900+
901+ QVariant volumeVariant (volume);
902+ bool isPropertyAssigned = pItem->setProperty (" volume" , volumeVariant);
903+
904+ if (!isPropertyAssigned){
905+ (*error) = new Error (kUnknownError ,
906+ std::string (" Error while executing comand: There is no such member or the parameters did not match" ));
907+ }
908+ }
909+
910+ void Quick2ViewCmdExecutor::GetPlayingPosition (const ElementId &element, double *position, Error **error)
911+ {
912+ QQuickView* view = getView (view_id_, error);
913+ if (NULL == view)
914+ return ;
915+
916+ QQuickItem* pItem = getElement (element, error);
917+ if (NULL == pItem)
918+ return ;
919+
920+
921+ base::Value* positionValue = NULL ;
922+ GetAttribute (element, " position" , &positionValue, error);
923+
924+ if ( error != NULL && *error != NULL && (*error)->code () != kSuccess ){
925+ return ;
926+ }
927+
928+ int positionInt;
929+ positionValue->GetAsInteger (&positionInt);
930+
931+ *position = positionInt/1000.0 ;
932+ }
933+
934+ void Quick2ViewCmdExecutor::SetPlayingPosition (const ElementId &element, double position, Error **error)
935+ {
936+ QQuickView* view = getView (view_id_, error);
937+ if (NULL == view)
938+ return ;
939+
940+ QQuickItem* pItem = getElement (element, error);
941+ if (NULL == pItem)
942+ return ;
943+
944+ QVariant positionVariant ((int )(position * 1000 ));
945+ bool isPropertyAssigned = pItem->setProperty (" position" , positionVariant);
946+
947+ if (!isPropertyAssigned){
948+ (*error) = new Error (kUnknownError ,
949+ std::string (" Error while executing comand: There is no such member or the parameters did not match" ));
950+ }
951+ }
952+
953+ void Quick2ViewCmdExecutor::SetMute (const ElementId &element, bool mute, Error **error)
954+ {
955+ QQuickView* view = getView (view_id_, error);
956+ if (NULL == view)
957+ return ;
958+
959+ QQuickItem* pItem = getElement (element, error);
960+ if (NULL == pItem)
961+ return ;
962+
963+ QVariant muteVariant (mute);
964+ bool isPropertyAssigned = pItem->setProperty (" muted" , muteVariant);
965+
966+ if (!isPropertyAssigned){
967+ (*error) = new Error (kUnknownError ,
968+ std::string (" Error while executing comand: There is no such member or the parameters did not match" ));
969+ }
970+ }
971+
972+ void Quick2ViewCmdExecutor::GetMute (const ElementId &element, bool *mute, Error **error)
973+ {
974+ QQuickView* view = getView (view_id_, error);
975+ if (NULL == view)
976+ return ;
977+
978+ QQuickItem* pItem = getElement (element, error);
979+ if (NULL == pItem)
980+ return ;
981+
982+
983+ base::Value* muteValue = NULL ;
984+ GetAttribute (element, " muted" , &muteValue, error);
985+
986+ if ( error != NULL && *error != NULL && (*error)->code () != kSuccess ){
987+ return ;
988+ }
989+
990+ muteValue->GetAsBoolean (mute);
991+ }
992+
818993QQuickItem* Quick2ViewCmdExecutor::getFocusItem (QQuickView* view) {
819994 QQuickItem* pFocusItem = view->activeFocusItem ();
820995 if (NULL != pFocusItem) return pFocusItem;
0 commit comments