Skip to content

Commit

Permalink
qmlplayer: load svg from qrc or disk by linking to libcommon(shared)
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 3, 2014
1 parent f6b9aea commit 969df72
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 3 additions & 1 deletion examples/QMLPlayer/QMLPlayer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ SOURCES += main.cpp
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

#QMAKE_LFLAGS += -u _link_hack
isEmpty(PROJECTROOT): PROJECTROOT = $$PWD/../..
include($${PROJECTROOT}/common.pri)
STATICLINK = 0
include($${PROJECTROOT}/examples/common/libcommon.pri)
preparePaths($$OUT_PWD/../../out)
2 changes: 1 addition & 1 deletion examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char *argv[])
json.prepend("[\"").append("\"]");
json.replace("\\", "/"); //FIXME
QMetaObject::invokeMethod(viewer.rootObject(), "init", Q_ARG(QVariant, json));
#else
//#else
if (app.arguments().size() > 1) {
qDebug("arguments > 1");
QObject *player = viewer.rootObject()->findChild<QObject*>("player");
Expand Down
29 changes: 19 additions & 10 deletions examples/QMLPlayer/qml/QMLPlayer/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ Rectangle {
height: 240
color: "black"

// "/xxx" will be resolved as qrc:///xxx. while "xxx" is "qrc:///QMLDIR/xxx
property string resprefix: Qt.resolvedUrl(" ").substring(0, 4) == "qrc:" ? "/" : ""
function init(argv) {
var a = JSON.parse(argv)
if (a.length > 1) {
player.source = a[a.length-1]
player.play()
// FIXME: source is relative to this qml
//player.source = a[a.length-1]
//player.play()
}
}
function resurl(s) { //why called twice if in qrc?
return resprefix + s
}

VideoOutput {
id: vo
Expand All @@ -48,6 +54,7 @@ Rectangle {
MediaPlayer {
id: player
objectName: "player"
//loops: MediaPlayer.Infinite
onPositionChanged: {
console.log("pos change")
progress.value = position/duration
Expand All @@ -66,6 +73,7 @@ Rectangle {
}
}

// TODO: Control.qml
Rectangle {
id: control
color: "black"
Expand Down Expand Up @@ -155,8 +163,9 @@ Rectangle {
bgColorSelected: "transparent"
width: 50
height: 50
icon: "play.svg"
iconChecked: "pause.svg"
icon: resurl("theme/default/play.svg")
iconChecked: resurl("theme/default/pause.svg")

onClicked: {
if (player.playbackState == MediaPlayer.StoppedState) {
player.play()
Expand All @@ -175,7 +184,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 35
height: 35
icon: "stop.svg"
icon: resurl("theme/default/stop.svg")
onClicked: {
player.stop()
}
Expand All @@ -186,7 +195,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 35
height: 35
icon: "backward.svg"
icon: resurl("theme/default/backward.svg")
onClicked: {
player.seek(player.position-10000)
}
Expand All @@ -202,7 +211,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 35
height: 35
icon: "forward.svg"
icon: resurl("theme/default/forward.svg")
onClicked: {
player.seek(player.position+10000)
}
Expand All @@ -218,7 +227,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 25
height: 25
icon: "info.svg"
icon: resurl("theme/default/info.svg")
visible: true
onClicked: help.visible = !help.visible
}
Expand All @@ -228,7 +237,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 25
height: 25
icon: "open.svg"
icon: resurl("theme/default/open.svg")
onClicked: fileDialog.open()
}
Button {
Expand All @@ -237,7 +246,7 @@ Rectangle {
bgColorSelected: "transparent"
width: 25
height: 25
icon: "help.svg"
icon: resurl("theme/default/help.svg")
onClicked: help.visible = !help.visible
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/examples.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TEMPLATE = subdirs

SUBDIRS += \
common \
sharedoutput \
vo-qt \
player \
Expand Down

0 comments on commit 969df72

Please sign in to comment.