Skip to content

Commit 23d8ceb

Browse files
Andrii BoichukAndrii Boichuk
authored andcommitted
Add QML remote player API
1 parent fd1aa6d commit 23d8ceb

File tree

3 files changed

+184
-9
lines changed

3 files changed

+184
-9
lines changed

inc/extension_qt/quick2_view_executor.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ class Quick2ViewCmdExecutor : public QWindowViewCmdExecutor {
9595
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
9696
virtual void TouchFlick(const int &xSpeed, const int &ySpeed, Error **error) NOT_SUPPORTED_IMPL;
9797
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) NOT_SUPPORTED_IMPL;
98-
virtual void GetPlayerState(const ElementId& element, PlayerState*, Error** error) NOT_SUPPORTED_IMPL;
99-
virtual void SetPlayerState(const ElementId& element, PlayerState, Error** error) NOT_SUPPORTED_IMPL;
100-
virtual void GetPlayerVolume(const ElementId& element, double*, Error** error) NOT_SUPPORTED_IMPL;
101-
virtual void SetPlayerVolume(const ElementId& element, double, Error** error) NOT_SUPPORTED_IMPL;
102-
virtual void GetPlayingPosition(const ElementId& element, double*, Error** error) NOT_SUPPORTED_IMPL;
103-
virtual void SetPlayingPosition(const ElementId& element, double, Error** error) NOT_SUPPORTED_IMPL;
104-
virtual void SetMute(const ElementId& element, bool, Error**error) NOT_SUPPORTED_IMPL;
105-
virtual void GetMute(const ElementId& element, bool*, Error**error) NOT_SUPPORTED_IMPL;
98+
virtual void GetPlayerState(const ElementId& element, PlayerState*, Error** error);
99+
virtual void SetPlayerState(const ElementId& element, PlayerState, Error** error);
100+
virtual void GetPlayerVolume(const ElementId& element, double*, Error** error);
101+
virtual void SetPlayerVolume(const ElementId& element, double, Error** error);
102+
virtual void GetPlayingPosition(const ElementId& element, double*, Error** error);
103+
virtual void SetPlayingPosition(const ElementId& element, double, Error** error);
104+
virtual void SetMute(const ElementId& element, bool, Error**error);
105+
virtual void GetMute(const ElementId& element, bool*, Error**error);
106106
virtual void VisualizerSource(std::string* source, Error** error) NOT_SUPPORTED_IMPL;
107107
virtual void VisualizerShowPoint(Error** error) NOT_SUPPORTED_IMPL;
108108

src/webdriver/extension_qt/quick2_view_executor.cc

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
818993
QQuickItem* Quick2ViewCmdExecutor::getFocusItem(QQuickView* view) {
819994
QQuickItem* pFocusItem = view->activeFocusItem();
820995
if (NULL != pFocusItem) return pFocusItem;

src/webdriver/extension_qt/widget_view_executor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ void QWidgetViewCmdExecutor::GetPlayingPosition(const ElementId &element, double
10261026
*error = new Error(kInvalidElementState);
10271027
return;
10281028
}
1029-
*position = player->position()*1.0;
1029+
*position = player->position()/1000.0;
10301030
#else
10311031
NOT_SUPPORTED_IMPL
10321032
#endif

0 commit comments

Comments
 (0)