Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickmediaplayer.cpp
Go to the documentation of this file.
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
#
include
"qquickmediaplayer_p.h"
5
6
#
include
<
QtMultimedia
/
private
/
qmediaplayer_p
.
h
>
7
#
include
<
QtMultimediaQuick
/
private
/
qqmlcontext_source_resolver_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
QQuickMediaPlayer::QQuickMediaPlayer(QObject *parent) : QMediaPlayer(parent)
12
{
13
connect(
this
, &QMediaPlayer::mediaStatusChanged,
this
,
14
&QQuickMediaPlayer::onMediaStatusChanged);
15
16
auto
*playerPrivate = QMediaPlayerPrivate::get(
this
);
17
playerPrivate->m_sourceResolver =
18
std::make_unique<QMultimediaPrivate::QQmlContextSourceResolver>(
this
);
19
}
20
21
void
QQuickMediaPlayer::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
22
{
23
if
(status != QMediaPlayer::LoadedMedia || std::exchange(m_wasMediaLoaded,
true
))
24
return
;
25
26
// run with QueuedConnection to make the user able to handle the media status change
27
// by themselves, otherwise play() might change the status in the handler.
28
auto
tryAutoPlay = [
this
]() {
29
if
(m_autoPlay && mediaStatus() == QMediaPlayer::LoadedMedia)
30
play();
31
};
32
33
if
(m_autoPlay)
34
QMetaObject::invokeMethod(
this
, tryAutoPlay, Qt::QueuedConnection);
35
}
36
37
/*!
38
\since 6.7
39
\qmlproperty bool QtMultimedia::MediaPlayer::autoPlay
40
41
This property controls whether the media begins to play automatically after it gets loaded.
42
Defaults to \c false.
43
*/
44
45
bool
QQuickMediaPlayer::autoPlay()
const
46
{
47
return
m_autoPlay;
48
}
49
50
void
QQuickMediaPlayer::setAutoPlay(
bool
autoPlay)
51
{
52
if
(std::exchange(m_autoPlay, autoPlay) != autoPlay)
53
Q_EMIT autoPlayChanged(autoPlay);
54
}
55
56
QT_END_NAMESPACE
57
58
#
include
"moc_qquickmediaplayer_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
multimediaquick
qquickmediaplayer.cpp
Generated on
for Qt by
1.18.0