summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/video/mediaplayer/controls/PlaybackControl.qml
blob: 056cf50d09ee4fa7935dd28759bb81dd7a0c88d5 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtMultimedia
import QtQuick.Dialogs

//! [0]
Item {
    id: playbackController

    required property MediaPlayer mediaPlayer
    required property MetadataInfo metadataInfo
    required property TracksInfo audioTracksInfo
    required property TracksInfo videoTracksInfo
    required property TracksInfo subtitleTracksInfo
    //! [0]

    property alias muted: audioControl.muted
    property alias volume: audioControl.volume

    property bool landscapePlaybackControls: root.width >= 668
    property bool busy: fileDialog.visible
                        || urlPopup.visible
                        || settingsPopup.visible
                        || audioControl.busy
                        || playbackSeekControl.busy
                        || !playbackController.mediaPlayer.playing

    implicitHeight: landscapePlaybackControls ? 168 : 208

    Behavior on opacity { NumberAnimation { duration: 300 } }

    FileDialog {
        id: fileDialog
        title: "Please choose a file"
        onAccepted: {
            playbackController.mediaPlayer.stop()
            playbackController.mediaPlayer.source = fileDialog.currentFile
            playbackController.mediaPlayer.play()
        }
    }

    UrlPopup {
        id: urlPopup
        anchors.centerIn: Overlay.overlay
        mediaPlayer: playbackController.mediaPlayer
    }

    SettingsPopup {
        id: settingsPopup
        anchors.centerIn: Overlay.overlay

        metadataInfo: playbackController.metadataInfo
        mediaPlayer: playbackController.mediaPlayer
        audioTracksInfo: playbackController.audioTracksInfo
        videoTracksInfo: playbackController.videoTracksInfo
        subtitleTracksInfo: playbackController.subtitleTracksInfo
    }

    component CustomButton: RoundButton {
        implicitWidth: 40
        implicitHeight: 40
        radius: 4
        icon.width: 24
        icon.height: 24
        flat: true
    }

    component CustomRoundButton: RoundButton {
        property int diameter: 40
        Layout.preferredWidth: diameter
        Layout.preferredHeight: diameter
        radius: diameter / 2
        icon.width: 24
        icon.height: 24
    }

    //! [1]
    CustomButton {
        id: fileDialogButton
        icon.source: "../images/open_new.svg"
        flat: false
        onClicked: fileDialog.open()
    }

    CustomButton {
        id: openUrlButton
        icon.source: "../images/link.svg"
        flat: false
        onClicked: urlPopup.open()
    }
    //! [1]

    CustomButton {
        id: loopButton
        icon.source: "../images/loop.svg"
        icon.color: playbackController.mediaPlayer.loops === MediaPlayer.Once ? palette.buttonText : palette.accent
        onClicked: playbackController.mediaPlayer.loops = playbackController.mediaPlayer.loops === MediaPlayer.Once
                   ? MediaPlayer.Infinite
                   : MediaPlayer.Once
    }

    CustomButton {
        id: settingsButton
        icon.source: "../images/more.svg"
        onClicked: settingsPopup.open()
    }

    CustomButton {
        id: fullScreenButton
        icon.source: root.fullScreen ? "../images/zoom_minimize.svg"
                                     : "../images/zoom_maximize.svg"
        onClicked: {
            root.fullScreen ?  root.showNormal() : root.showFullScreen()
            root.fullScreen = !root.fullScreen
        }
    }

    RowLayout {
        id: controlButtons
        spacing: 16

        CustomRoundButton {
            id: backward10Button
            icon.source: "../images/backward10.svg"
            onClicked: {
                const pos = Math.max(0, playbackController.mediaPlayer.position - 10000)
                playbackController.mediaPlayer.setPosition(pos)
            }
        }

        //! [2]
        CustomRoundButton {
            id: playButton
            visible: playbackController.mediaPlayer.playbackState !== MediaPlayer.PlayingState
            icon.source: "../images/play_symbol.svg"
            onClicked: playbackController.mediaPlayer.play()
        }

        CustomRoundButton {
            id: pauseButton
            visible: playbackController.mediaPlayer.playbackState === MediaPlayer.PlayingState
            icon.source: "../images/pause_symbol.svg"
            onClicked: playbackController.mediaPlayer.pause()
        }
        //! [2]

        //! [3]
        CustomRoundButton {
            id: forward10Button
            icon.source: "../images/forward10.svg"
            onClicked: {
                const pos = Math.min(playbackController.mediaPlayer.duration,
                                   playbackController.mediaPlayer.position + 10000)
                playbackController.mediaPlayer.setPosition(pos)
            }
        }
        //! [3]
    } // RowLayout controlButtons

    AudioControl {
        id: audioControl
        showSlider: root.width >= 960
    }

    PlaybackSeekControl {
        id: playbackSeekControl
        Layout.fillWidth: true
        mediaPlayer: playbackController.mediaPlayer
    }

    Frame {
        id: landscapeLayout
        anchors.fill: parent
        padding: 32
        topPadding: 28
        visible: landscapePlaybackControls
        background: Rectangle {
            color: "#F6F6F6"
        }

        ColumnLayout {
            anchors.fill: parent
            spacing: 16

            Item {
                Layout.fillWidth: true
                implicitHeight: 40

                LayoutItemProxy {
                    id: fdbProxy
                    target: fileDialogButton
                    anchors.left: parent.left
                }

                LayoutItemProxy {
                    target: openUrlButton
                    anchors.left: fdbProxy.right
                    anchors.leftMargin: 12
                }

                LayoutItemProxy {
                    target: controlButtons
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                LayoutItemProxy {
                    target: loopButton
                    anchors.right: acProxy.left
                    anchors.rightMargin: 12
                }

                LayoutItemProxy {
                    id: acProxy
                    target: audioControl
                    anchors.right: sbProxy.left
                    anchors.rightMargin: 30
                    anchors.verticalCenter: parent.verticalCenter
                }

                LayoutItemProxy {
                    id: sbProxy
                    target: settingsButton
                    anchors.right: fbProxy.left
                    anchors.rightMargin: 12
                }

                LayoutItemProxy {
                    id: fbProxy
                    target: fullScreenButton
                    anchors.right: parent.right
                }
            } // Item

            LayoutItemProxy {
                target: playbackSeekControl
                Layout.topMargin: 16
                Layout.bottomMargin: 16
            }
        }
    } // Frame frame

    Frame {
        id: portraitLayout
        anchors.fill: parent
        padding: 32
        topPadding: 28
        visible: !landscapePlaybackControls
        background: Rectangle {
            color: "#F6F6F6"
        }

        ColumnLayout {
            anchors.fill: parent
            spacing: 16

            Item {
                Layout.fillWidth: true
                implicitHeight: 40

                LayoutItemProxy {
                    target: loopButton
                    anchors.right: cbProxy.left
                    anchors.rightMargin: 16
                }

                LayoutItemProxy {
                    id: cbProxy
                    target: controlButtons
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                LayoutItemProxy {
                    target: audioControl
                    anchors.left: cbProxy.right
                    anchors.leftMargin: 16
                }
            }
            Item {
                Layout.fillWidth: true
                implicitHeight: 40

                LayoutItemProxy {
                    id: fdbProxy_
                    target: fileDialogButton
                    anchors.left: parent.left
                }

                LayoutItemProxy {
                    target: openUrlButton
                    anchors.left: fdbProxy_.right
                    anchors.leftMargin: 12
                }

                LayoutItemProxy {
                    target: settingsButton
                    anchors.right: fbProxy_.left
                    anchors.rightMargin: 12
                }

                LayoutItemProxy {
                    id: fbProxy_
                    target: fullScreenButton
                    anchors.right: parent.right
                }
            }

            LayoutItemProxy {
                target: playbackSeekControl
                Layout.topMargin: 8
                Layout.bottomMargin: 8
            }
        }
    }
}