summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-03-30 13:15:29 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-04-06 21:30:16 -0700
commit416b30f8e23e64daeb7d1a72a231863cfe9f9b53 (patch)
tree821ca6eb3abde26bf03d66cbba951f4de5ae8c4f
parent0223839486802f3944df6e20b73dc93fa4a03727 (diff)
libqtappfw: mediaplayer: initial agl-service-mediaplayer binding support
Add initial support interface between agl-service-mediaplayer and libqtappfw Bug-AGL: SPEC-1375 Change-Id: I740d8cddfd73198b7a3246cb46c941da9f3175d1 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
-rw-r--r--CMakeLists.txt7
-rw-r--r--mediaplayer.cpp171
-rw-r--r--mediaplayer.h65
-rw-r--r--mediaplayermessage.cpp31
-rw-r--r--mediaplayermessage.h31
-rw-r--r--message.h1
-rw-r--r--messageengine.cpp4
7 files changed, 308 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f91d1e..64d377b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,12 +14,15 @@ CONFIGURE_FILE("qtappfw.pc.in" "qtappfw.pc" @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw.pc
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-add_library(qtappfw SHARED message.cpp messageengine.cpp telephony.cpp telephonymessage.cpp weather.cpp weathermessage.cpp)
+add_library(qtappfw SHARED message.cpp messageengine.cpp
+ mediaplayer.cpp mediaplayermessage.cpp
+ telephony.cpp telephonymessage.cpp
+ weather.cpp weathermessage.cpp)
target_link_libraries(qtappfw Qt5::WebSockets)
set_target_properties(qtappfw PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
- PUBLIC_HEADER "message.h;messageengine.h;telephony.h;telephonymessage.h;weather.h;weathermessage.h")
+ PUBLIC_HEADER "message.h;messageengine.h;mediaplayer.h;mediaplayermessage.h;telephony.h;telephonymessage.h;weather.h;weathermessage.h")
target_include_directories(qtappfw PRIVATE .)
install(TARGETS qtappfw
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/mediaplayer.cpp b/mediaplayer.cpp
new file mode 100644
index 0000000..58aad8a
--- /dev/null
+++ b/mediaplayer.cpp
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2018 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "message.h"
+#include "messageengine.h"
+#include "mediaplayer.h"
+#include "mediaplayermessage.h"
+
+Mediaplayer::Mediaplayer (QUrl &url, QObject * parent) :
+ QObject(parent),
+ m_mloop(nullptr)
+{
+ m_mloop = new MessageEngine(url);
+ QObject::connect(m_mloop, &MessageEngine::connected, this, &Mediaplayer::onConnected);
+ QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Mediaplayer::onDisconnected);
+ QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Mediaplayer::onMessageReceived);
+}
+
+Mediaplayer::~Mediaplayer()
+{
+ delete m_mloop;
+}
+
+
+// Control Verb methods
+
+void Mediaplayer::control(QString control, QJsonObject parameter)
+{
+ MediaplayerMessage *tmsg = new MediaplayerMessage();
+
+ parameter.insert("value", control);
+
+ tmsg->createRequest("controls", parameter);
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+}
+
+
+void Mediaplayer::control(QString control)
+{
+ QJsonObject parameter;
+
+ Mediaplayer::control(control, parameter);
+}
+
+void Mediaplayer::play()
+{
+ control("play");
+}
+
+void Mediaplayer::pause()
+{
+ control("pause");
+}
+
+void Mediaplayer::previous()
+{
+ control("previous");
+}
+
+void Mediaplayer::next()
+{
+ control("next");
+}
+
+void Mediaplayer::seek(int milliseconds)
+{
+ QJsonObject parameter;
+ parameter.insert("position", QString::number(milliseconds));
+
+ control("seek", parameter);
+}
+
+void Mediaplayer::fastforward(int milliseconds)
+{
+ QJsonObject parameter;
+ parameter.insert("position", QString::number(milliseconds));
+
+ control("fast-forward", parameter);
+}
+
+void Mediaplayer::rewind(int milliseconds)
+{
+ QJsonObject parameter;
+ parameter.insert("position", QString::number(milliseconds));
+
+ control("rewind", parameter);
+}
+
+void Mediaplayer::picktrack(int track)
+{
+ QJsonObject parameter;
+ parameter.insert("index", QString::number(track));
+
+ control("pick-track", parameter);
+}
+
+void Mediaplayer::volume(int volume)
+{
+ QJsonObject parameter;
+ parameter.insert("volume", QString(volume));
+
+ control("volume", parameter);
+}
+
+void Mediaplayer::loop(int state)
+{
+ QJsonObject parameter;
+ parameter.insert("state", state ? "true" : "false");
+
+ control("loop", parameter);
+}
+
+void Mediaplayer::onConnected()
+{
+ QStringListIterator eventIterator(events);
+ MediaplayerMessage *tmsg;
+
+ while (eventIterator.hasNext()) {
+ tmsg = new MediaplayerMessage();
+ QJsonObject parameter;
+ parameter.insert("value", eventIterator.next());
+ tmsg->createRequest("subscribe", parameter);
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+ }
+}
+
+void Mediaplayer::onDisconnected()
+{
+ QStringListIterator eventIterator(events);
+ MediaplayerMessage *tmsg;
+
+ while (eventIterator.hasNext()) {
+ tmsg = new MediaplayerMessage();
+ QJsonObject parameter;
+ parameter.insert("value", eventIterator.next());
+ tmsg->createRequest("unsubscribe", parameter);
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+ }
+}
+
+void Mediaplayer::onMessageReceived(MessageType type, Message *message)
+{
+ if (type == MediaplayerEventMessage) {
+ MediaplayerMessage *tmsg = qobject_cast<MediaplayerMessage*>(message);
+
+ if (tmsg->isEvent()) {
+ if (tmsg->isPlaylistEvent()) {
+ emit playlistChanged(tmsg->eventData());
+ } else if (tmsg->isMetadataEvent()) {
+ emit metadataChanged(tmsg->eventData());
+ }
+ }
+ }
+ message->deleteLater();
+}
diff --git a/mediaplayer.h b/mediaplayer.h
new file mode 100644
index 0000000..107cfa3
--- /dev/null
+++ b/mediaplayer.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2018 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MEDIAPLAYER_H
+#define MEDIAPLAYER_H
+
+#include <QDebug>
+#include <QObject>
+
+#include "messageengine.h"
+
+class Mediaplayer : public QObject
+{
+ Q_OBJECT
+
+ public:
+ explicit Mediaplayer(QUrl &url, QObject * parent = Q_NULLPTR);
+ virtual ~Mediaplayer();
+
+ // controls
+ Q_INVOKABLE void play();
+ Q_INVOKABLE void pause();
+ Q_INVOKABLE void previous();
+ Q_INVOKABLE void next();
+ Q_INVOKABLE void seek(int);
+ Q_INVOKABLE void fastforward(int);
+ Q_INVOKABLE void rewind(int);
+ Q_INVOKABLE void picktrack(int);
+ Q_INVOKABLE void volume(int);
+ Q_INVOKABLE void loop(int);
+
+ signals:
+ void playlistChanged(QJsonObject playlist);
+ void metadataChanged(QJsonObject metadata);
+
+ private:
+ MessageEngine *m_mloop;
+
+ void control(QString, QJsonObject);
+ void control(QString);
+
+ void onConnected();
+ void onDisconnected();
+ void onMessageReceived(MessageType, Message*);
+
+ const QStringList events {
+ "playlist",
+ "metadata",
+ };
+};
+
+#endif // MEDIAPLAYER_H
diff --git a/mediaplayermessage.cpp b/mediaplayermessage.cpp
new file mode 100644
index 0000000..cda09d2
--- /dev/null
+++ b/mediaplayermessage.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2018 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <QDebug>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+#include "mediaplayermessage.h"
+
+bool MediaplayerMessage::createRequest(QString verb, QJsonObject parameter)
+{
+ QStringList verbs {"playlist", "metadata", "controls", "subscribe", "unsubscribe"};
+ if (!verbs.contains(verb))
+ return false;
+
+ return Message::createRequest("mediaplayer", verb, parameter);
+}
diff --git a/mediaplayermessage.h b/mediaplayermessage.h
new file mode 100644
index 0000000..c164cde
--- /dev/null
+++ b/mediaplayermessage.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2018 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MEDIAPLAYER_MESSAGE_H
+#define MEDIAPLAYER_MESSAGE_H
+
+#include "message.h"
+
+class MediaplayerMessage : public Message
+{
+ Q_OBJECT
+ public:
+ bool isPlaylistEvent() { return (this->eventName() == "playlist"); };
+ bool isMetadataEvent() { return (this->eventName() == "metadata"); };
+ bool createRequest(QString verb, QJsonObject parameter);
+};
+
+#endif // MEDIAPLAYER_MESSAGE_H
diff --git a/message.h b/message.h
index 28df8d0..8512332 100644
--- a/message.h
+++ b/message.h
@@ -32,6 +32,7 @@ enum MessageType {
GenericMessage,
TelephonyEventMessage,
WeatherEventMessage,
+ MediaplayerEventMessage,
};
class Message : public QObject
diff --git a/messageengine.cpp b/messageengine.cpp
index 101f7e0..916fb25 100644
--- a/messageengine.cpp
+++ b/messageengine.cpp
@@ -16,6 +16,7 @@
#include "message.h"
#include "messageengine.h"
+#include "mediaplayermessage.h"
#include "telephonymessage.h"
#include "weathermessage.h"
@@ -78,6 +79,9 @@ void MessageEngine::onTextMessageReceived(QString jsonStr)
} else if (api == "weather") {
message = new WeatherMessage;
type = WeatherEventMessage;
+ } else if (api == "mediaplayer") {
+ message = new MediaplayerMessage;
+ type = MediaplayerEventMessage;
} else {
message = new Message;
type = GenericMessage;