Хочу юзать Phonon::VideoPlayer в QML, делаю так:
qmlphononvideoplayer.h
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| #ifndef QMLPHONONVIDEOPLAYER_H
#define QMLPHONONVIDEOPLAYER_H
#include <QDeclarativeItem>
#include <Phonon>
#include <QScopedPointer>
#include <QUrl>
#include <QGraphicsProxyWidget>
class QmlPhononVideoPlayer : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(qreal x READ getX WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal y READ getY WRITE setY NOTIFY yChanged)
Q_PROPERTY(qreal z READ getZ WRITE setZ NOTIFY zChanged)
Q_PROPERTY(int width READ width)
Q_PROPERTY(int height READ height)
public:
explicit QmlPhononVideoPlayer(QDeclarativeItem *parent = 0);
inline void setX(qreal x) {proxy->setX(x);}
inline qreal getX() {return proxy->x();}
inline void setY(qreal y) {proxy->setY(y);}
inline qreal getY() {return proxy->y();}
inline void setZ(qreal z) {proxy->setZValue(z);}
inline qreal getZ() {return proxy->zValue();}
inline int width() {return player->width();}
inline int height() {return player->height();}
signals:
void finished ();
void xChanged();
void yChanged();
void zChanged();
public slots:
inline void load ( const QString& path ) { player->load(path); }// player->resize(player->sizeHint()); }
inline void pause () { player->pause(); }
inline void play ( const QString& path ) { player->play(path); }
inline void play () { player->play(); }
inline void seek ( qint64 ms ) { player->seek(ms); }
inline void setVolume ( float volume ) { player->setVolume(volume); }
inline void stop () { player->stop(); }
private:
QGraphicsProxyWidget* proxy;
QScopedPointer <Phonon::VideoPlayer> player;
};
#endif // QMLPHONONVIDEOPLAYER_H |
|
qmlphononvideoplayer.cpp
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
| #include "qmlphononvideoplayer.h"
QmlPhononVideoPlayer::QmlPhononVideoPlayer(QDeclarativeItem *parent) :
QDeclarativeItem(parent),
proxy(new QGraphicsProxyWidget(this)),
player(new Phonon::VideoPlayer(Phonon::VideoCategory))
{
proxy->setWidget(player.data());
QObject::connect(player.data(), SIGNAL(finished()), this, SIGNAL(finished()));
proxy->setX(0);
proxy->setY(0);
proxy->setZValue(0);
} |
|
mainvindow.h
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| #ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtDeclarative/QDeclarativeView>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
void quit();
private:
QDeclarativeView *ui;
};
#endif // MAINWINDOW_H |
|
mainwindow.cpp
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
ui = new QDeclarativeView;
ui->setSource(QUrl("../../../src/tests/qt/QView/qml/main.qml"));
setCentralWidget(ui);
QObject::connect((QObject*)ui->engine(), SIGNAL(quit()), (QObject*)this, SIGNAL(quit()));
}
MainWindow::~MainWindow()
{
delete ui;
} |
|
main.cpp
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #include <QApplication>
#include <QDeclarativeView>
#include <QUrl>
#include <QtDeclarative>
#include "qmlphononvideoplayer.h"
#include "mainwindow.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<QmlPhononVideoPlayer>("QmlPhononVideoPlayer", 1, 0, "QmlPhononVideoPlayer");
MainWindow w;
QObject::connect(&w, SIGNAL(quit()), &app, SLOT(quit()));
w.show();
return app.exec();
} |
|
SimpleVideoPlayer.qml
Javascript |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| import QtQuick 1.0
import QmlPhononVideoPlayer 1.0
Rectangle {
id: player
width: videoPlayer.width
height: videoPlayer.height
color: "grey"
signal finished
QmlPhononVideoPlayer {
x: 0; y: 0
id: videoPlayer
// Component.onCompleted: finished.connect(player.finished)
// Connections { target: videoPlayer; onFinished: {} }
}
Item {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: playerControl.width
height: playerControl.height
MouseArea{
id:mouseArea
anchors.fill: parent
hoverEnabled: true
onEntered: {
playerControl.opacity = 1
}
onExited: {
playerControl.opacity = 0
}
}
}
Rectangle {
width: parent.width
height: 40
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
id: playerControl
color: "#20FFFFFF"
opacity: 0
// radius: 10
// smooth: true
// border.width: 5
// border.color: "white"
Row {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
spacing: 20
Button {
text: "Open"
onClicked: {
videoPlayer.load("d:/test/video/1.mp4");
}
}
Button {
text: "Play"
onClicked: {
videoPlayer.play();
}
}
Button {
text: "Pause"
onClicked: {
videoPlayer.pause();
}
}
Button {
text: "Stop"
onClicked: {
videoPlayer.stop();
}
}
}
Behavior on opacity {
NumberAnimation { duration: 100 }
}
}
} |
|
Button.qml
Javascript |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| import QtQuick 1.0
Rectangle {
id: button
property variant text
signal clicked
height: text.height + 10
width: text.width + 20
radius: 5
smooth: true
gradient: Gradient {
GradientStop {
position: 0.0
color: !mouseArea.pressed ? activePalette.light : activePalette.dark
}
GradientStop {
position: 0.5
color: !mouseArea.pressed ? activePalette.dark : activePalette.light
}
GradientStop {
position: 1.0
color: !mouseArea.pressed ? activePalette.light : activePalette.dark
}
}
SystemPalette { id: activePalette }
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: button.clicked()
}
Text {
id: text
anchors.centerIn:parent
font.pointSize: 10
font.family: "Courier"
font.bold: true
font.capitalization: Font.AllUppercase
style: Text.Sunken
text: button.text
color: "#80808080"
}
} |
|
main.qml
Javascript |
1
2
3
4
5
6
7
8
| import QtQuick 1.0
import Qt 4.7
import QmlPhononVideoPlayer 1.0
SimpleVideoPlayer {
x:0; y:0
} |
|
Проблема при проигрывании видео такая: виджет с плеером всегда одинакогого размера (640x480), а видео он проигрывает всегда в одинаковым широкоформатном разрешении (растягивает), даже если видео подходящего формата. Сверху и снизу остаются чёрные полосы.
От чего это может зависеть?
Как изменить формат?
P.S. Вопрос про форум: как сделать чтобы код сворачивался? а то слишком большой посл получается..