1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKMEDIAPLAYER_H
5#define QQUICKMEDIAPLAYER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QMediaPlayer>
19#include <QtQml/qqml.h>
20#include <qtmultimediaquickexports.h>
21#include <qurl.h>
22#include <private/qglobal_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class Q_MULTIMEDIAQUICK_EXPORT QQuickMediaPlayer : public QMediaPlayer
27{
28 Q_OBJECT
29 Q_PROPERTY(QUrl source READ qmlSource WRITE qmlSetSource NOTIFY qmlSourceChanged FINAL)
30
31 // qml doesn't support qint64, so we have to convert to the supported type.
32 // Int is expected to be enough for actual purposes.
33 Q_PROPERTY(int duration READ qmlDuration NOTIFY qmlDurationChanged FINAL)
34 Q_PROPERTY(int position READ qmlPosition WRITE setQmlPosition NOTIFY qmlPositionChanged FINAL)
35 Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged FINAL)
36
37 QML_NAMED_ELEMENT(MediaPlayer)
38
39public:
40 QQuickMediaPlayer(QObject *parent = nullptr);
41
42 void qmlSetSource(const QUrl &source);
43
44 QUrl qmlSource() const;
45
46 void setQmlPosition(int position);
47
48 int qmlPosition() const;
49
50 int qmlDuration() const;
51
52 bool autoPlay() const;
53
54 void setAutoPlay(bool autoPlay);
55
56private:
57 void onPositionChanged(qint64 position);
58 void onDurationChanged(qint64 position);
59 void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
60
61Q_SIGNALS:
62 void qmlSourceChanged(const QUrl &source);
63 void qmlPositionChanged(int position);
64 void qmlDurationChanged(int duration);
65 void autoPlayChanged(bool autoPlay);
66
67private:
68 QUrl m_source;
69 bool m_autoPlay = false;
70 bool m_wasMediaLoaded = false;
71};
72
73QT_END_NAMESPACE
74
75#endif
76

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/multimediaquick/qquickmediaplayer_p.h