From: Mohammed Sameer Date: Tue, 17 Sep 2013 00:19:06 +0000 (+0300) Subject: Added the ability to control playback volume from post capture X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=dbaa2edf6d8c6b29c5d899c7f98ac2f42472c3e1;ds=sidebyside Added the ability to control playback volume from post capture --- diff --git a/declarative/videoplayer.cpp b/declarative/videoplayer.cpp index 698d0ed..8ab4017 100644 --- a/declarative/videoplayer.cpp +++ b/declarative/videoplayer.cpp @@ -29,6 +29,7 @@ #include "qtcamviewfinderrenderer.h" #include #include +#include #if defined(QT4) VideoPlayer::VideoPlayer(QDeclarativeItem *parent) : @@ -107,6 +108,7 @@ void VideoPlayer::classBegin() { return; } + g_signal_connect (G_OBJECT (m_bin), "notify::volume", G_CALLBACK (on_volume_changed), this); g_object_set (m_bin, "flags", 99, NULL); GstElement *elem = gst_element_factory_make("pulsesink", "VideoPlayerPulseSink"); @@ -430,3 +432,29 @@ gboolean VideoPlayer::bus_call(GstBus *bus, GstMessage *msg, gpointer data) { void VideoPlayer::updateRequested() { update(); } + +quint32 VideoPlayer::volume() { + double vol = 1.0; + g_object_get (m_bin, "volume", &vol, NULL); + + qint32 res = (int)round(vol * 100.0); + + return res; +} + +void VideoPlayer::setVolume(quint32 volume) { + if (VideoPlayer::volume() != volume) { + double vol = volume / 100.0; + g_object_set (m_bin, "volume", vol, NULL); + emit volumeChanged(); + } +} + +void VideoPlayer::on_volume_changed(GObject *object, GParamSpec *pspec, gpointer user_data) { + Q_UNUSED(object); + Q_UNUSED(pspec); + + VideoPlayer *player = (VideoPlayer *) user_data; + + QMetaObject::invokeMethod(player, "volumeChanged", Qt::QueuedConnection); +} diff --git a/declarative/videoplayer.h b/declarative/videoplayer.h index d944b3b..c8aeb97 100644 --- a/declarative/videoplayer.h +++ b/declarative/videoplayer.h @@ -47,6 +47,7 @@ class VideoPlayer : public QQuickPaintedItem { Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged); Q_PROPERTY(State state READ state NOTIFY stateChanged); Q_ENUMS(State); + Q_PROPERTY(quint32 volume READ volume WRITE setVolume NOTIFY volumeChanged); public: @@ -90,6 +91,9 @@ public: State state() const; + quint32 volume(); + void setVolume(quint32 volume); + signals: void sourceChanged(); void cameraConfigChanged(); @@ -98,6 +102,7 @@ signals: void positionChanged(); void error(const QString& message, int code, const QString& debug); void stateChanged(); + void volumeChanged(); protected: void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry); @@ -107,6 +112,7 @@ private slots: private: static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data); + static void on_volume_changed(GObject *object, GParamSpec *pspec, gpointer user_data); bool setState(const State& state); diff --git a/qml/VideoPlayerPage.qml b/qml/VideoPlayerPage.qml index 2e310bf..8d78df3 100644 --- a/qml/VideoPlayerPage.qml +++ b/qml/VideoPlayerPage.qml @@ -55,7 +55,44 @@ Item { onTriggered: toolBar.show = false } + DeviceKeys { + id: zoomKeys + active: Qt.application.active && pipelineManager.scaleAcquired + repeat: true + + onVolumeUpPressed: { + timer.restart() + video.volume = Math.min(video.volume + 2, 100) + } + + onVolumeDownPressed: { + timer.restart() + video.volume = Math.max(video.volume - 2, 0) + } + } + VideoPlayer { + Rectangle { + id: volumeControl + anchors.top: parent.top + anchors.left: parent.left + width: (parent.width * video.volume) / 100 + color: "blue" + border.color: "black" + height: 25 + opacity: timer.running ? 1.0 : 0.0 + + Behavior on opacity { + NumberAnimation { duration: 250 } + } + + Timer { + id: timer + interval: 500 + repeat: false + } + } + id: video anchors.fill: parent cameraConfig: camera.cameraConfig diff --git a/src/cameraresources.cpp b/src/cameraresources.cpp index 91b06d7..cbaed5c 100644 --- a/src/cameraresources.cpp +++ b/src/cameraresources.cpp @@ -225,7 +225,8 @@ void CameraResourcesWorker::acquire(bool *ok, const CameraResources::Mode& mode) *ok = updateSet(QList() << ResourcePolicy::VideoPlaybackType << ResourcePolicy::AudioPlaybackType, - QList()); + QList() + << ResourcePolicy::ScaleButtonType); break; default: