summaryrefslogtreecommitdiffstats
path: root/basicsuite/Media Player/ControlBar.qml
blob: 1778728f624e9d223d3f42c900c1d3aec6a2efe4 (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

import QtQuick 2.0
import QtMultimedia 5.0

Rectangle {
    id: controlBar
    height: 150
    color: "#88333333"

    property MediaPlayer mediaPlayer: null
    property bool isMouseAbove: false

    signal openFile()
    signal openCamera()
    signal openURL()
    signal openFX()
    signal toggleFullScreen()

    state: "VISIBLE"

    onMediaPlayerChanged: {
        if (mediaPlayer === null)
            return;
        volumeControl.volume = mediaPlayer.volume;
    }

//    MouseArea {
//        anchors.fill: controlBar
//        hoverEnabled: true

//        onEntered: controlBar.isMouseAbove = true;
//        onExited: controlBar.isMouseAbove = false;
//    }

    function statusString(stat)
    {
        if (stat === MediaPlayer.NoMedia)
            return "No Media";
        else if (stat === MediaPlayer.Loading)
            return "Loading";
        else if (stat === MediaPlayer.Loaded)
            return "Loaded";
        else if (stat === MediaPlayer.Buffering)
            return "Buffering";
        else if (stat === MediaPlayer.Stalled)
            return "Stalled";
        else if (stat === MediaPlayer.Buffered)
            return "Buffered";
        else if (stat === MediaPlayer.EndOfMedia)
            return "EndOfMedia";
        else if (stat === MediaPlayer.InvalidMedia)
            return "InvalidMedia";
        else if (stat === MediaPlayer.UnknownStatus)
            return "UnknownStatus";
    }

//    Text {
//        id: statusText
//        anchors.left: parent.left
//        anchors.bottom: parent.top
//        anchors.bottomMargin: 12
//        font.pixelSize: 18
//        color: "white"
//        text: "Status: " + statusString(mediaPlayer.status)
//    }

//    Text {
//        anchors.verticalCenter: statusText.verticalCenter
//        anchors.left: statusText.right
//        anchors.leftMargin: 16
//        font.pixelSize: 18
//        color: "white"
//        text: Math.round(mediaPlayer.bufferProgress * 100.0) + "%"
//    }

    VolumeControl {
        id: volumeControl
        anchors.verticalCenter: playbackControl.verticalCenter
        anchors.left: controlBar.left
        anchors.leftMargin: 15
        onVolumeChanged: mediaPlayer.volume = volume

        Component.onCompleted: {
            volumeControl.volume = 0.5;
        }

        Connections {
            target: mediaPlayer
            onVolumeChanged: volumeControl.volume = mediaPlayer.volume
        }
    }

    //Playback Controls
    PlaybackControl {
        id: playbackControl
        anchors.horizontalCenter: controlBar.horizontalCenter
        anchors.bottom: seekControl.top
        anchors.bottomMargin: 20

        onPlayButtonPressed: {
            if (isPlaying) {
                mediaPlayer.pause();
            } else {
                mediaPlayer.play();
            }
        }

        onReverseButtonPressed: {
            if (mediaPlayer.seekable) {
                //Subtract 10 seconds
                mediaPlayer.seek(normalizeSeek(Math.round(-mediaPlayer.duration * 0.1)));
            }
        }

        onForwardButtonPressed: {
            if (mediaPlayer.seekable) {
                //Add 10 seconds
                mediaPlayer.seek(normalizeSeek(Math.round(mediaPlayer.duration * 0.1)));
            }
        }

        onStopButtonPressed: mediaPlayer.stop();
    }

    //Toolbar Controls
    Row {
        id: toolbarMenuButtons
        anchors.right: controlBar.right
        anchors.rightMargin: 15
        anchors.verticalCenter: playbackControl.verticalCenter
        spacing: 22

        ImageButton {
            id: fxButton
            imageSource: "images/FXButton.png"
            checkable: true
            checked: effectSelectionPanel.visible
            onClicked: {
                openFX();
            }
        }
        ImageButton {
            id: fileButton
            imageSource: "images/FileButton.png"
            onClicked: {
                openFile();
            }
        }
        ImageButton {
            id: urlButton
            imageSource: "images/UrlButton.png"
            onClicked: {
                openURL();
            }
        }
    }

//    ImageButton {
//        id: fullscreenButton
//        imageSource: "images/FullscreenButton.png"
//        onClicked: {
//            //Toggle fullscreen
//            toggleFullScreen();
//        }
//        checkable: true
//        checked: applicationWindow.isFullScreen
//        anchors.right: controlBar.right
//        anchors.top: controlBar.top
//        anchors.rightMargin: 15
//        anchors.topMargin: 15
//    }

    //Seek controls
    SeekControl {
        id: seekControl
        anchors.bottom: controlBar.bottom
        anchors.bottomMargin: 10
        anchors.right: controlBar.right
        anchors.left: controlBar.left
        anchors.rightMargin: 15
        anchors.leftMargin: 15
        enabled: playbackControl.isPlaybackEnabled

        duration: mediaPlayer.duration

        onSeekValueChanged: {
            mediaPlayer.seek(newPosition);
            position = mediaPlayer.position;
        }

        Component.onCompleted: {
            seekable = mediaPlayer.seekable;
        }
    }

    Connections {
        target: mediaPlayer
        onPositionChanged: {
            if (!seekControl.pressed) seekControl.position = mediaPlayer.position;
        }
        onStatusChanged: {
            if ((mediaPlayer.status == MediaPlayer.Loaded) || (mediaPlayer.status == MediaPlayer.Buffered) || mediaPlayer.status === MediaPlayer.Buffering || mediaPlayer.status === MediaPlayer.EndOfMedia)
                playbackControl.isPlaybackEnabled = true;
            else
                playbackControl.isPlaybackEnabled = false;
        }
        onPlaybackStateChanged: {
            if (mediaPlayer.playbackState === MediaPlayer.PlayingState) {
                playbackControl.isPlaying = true;
                applicationWindow.resetTimer();
            } else {
                show();
                playbackControl.isPlaying = false;
            }
        }

        onSeekableChanged: {
            // console.log("seekableChanged: " + mediaPlayer.seekable);
            seekControl.seekable = mediaPlayer.seekable;
        }
    }

    function hide() {
        controlBar.state = "HIDDEN";
    }

    function show() {
        controlBar.state = "VISIBLE";
    }

    //Usage: give the value you wish to modify position,
    //returns a value between 0 and duration
    function normalizeSeek(value) {
        var newPosition = mediaPlayer.position + value;
        if (newPosition < 0)
            newPosition = 0;
        else if (newPosition > mediaPlayer.duration)
            newPosition = mediaPlayer.duration;
        return newPosition;
    }

    states: [
        State {
            name: "HIDDEN"
            PropertyChanges {
                target: controlBar
                opacity: 0.0
            }
        },
        State {
            name: "VISIBLE"
            PropertyChanges {
                target: controlBar
                opacity: 0.95
            }
        }
    ]

    transitions: [
        Transition {
            from: "HIDDEN"
            to: "VISIBLE"
            NumberAnimation {
                id: showAnimation
                target: controlBar
                properties: "opacity"
                from: 0.0
                to: 1.0
                duration: 200
            }
        },
        Transition {
            from: "VISIBLE"
            to: "HIDDEN"
            NumberAnimation {
                id: hideAnimation
                target: controlBar
                properties: "opacity"
                from: 0.95
                to: 0.0
                duration: 200
            }
        }
    ]
}